Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
First, you have to the mysql.connector
. In case you are not sure of find out how to get this setup, consult with The best way to Set up MySQL Driver in Python.
You merely specify the WHERE
clause in your SQL assertion as follows:
import mysql.connector
mydb = mysql.connector.join(
host = "localhost",
person = "username",
password = "YoUrPaSsWoRd",
database = "your_database"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM clients WHERE deal with ='London Street'"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
print(x)
To filter wildcard characters
, you mix the WHERE
and LIKE
key phrases, and place the %
image the place the wildcards would happen.
Within the under instance, we are saying something that has the phrase highway
in it someplace. Be aware that this may exclude values that both begin or finish with highway
.
import mysql.connector
mydb = mysql.connector.join(
host = "localhost",
person = "username",
password = "YoUrPaSsWoRd",
database = "your_database"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM clients WHERE deal with LIKE '%highway%'"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
print(x)
As an alternative of passing dynamic values immediately into your question, relatively move them because the second argument to the execute
command, as a set
.
import mysql.connector
mydb = mysql.connector.join(
host = "localhost",
person = "username",
password = "YoUrPaSsWoRd",
database = "your_database"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM clients WHERE deal with = %s"
adr = ("Maple Drive", )
mycursor.execute(sql, adr)
myresult = mycursor.fetchall()
for x in myresult:
print(x)