SELECT records Python MySql
Database में table से record देखने या लाने के लिए SELECT FROM SQL स्टेटमेंट का उपयोग करना होता है।
SELECT all columns
SELECT * FROM employee
import mysql.connector
db = mysql.connector.connect(
host="localhost", user="username", passwd="password", database="dbname"
)
crsr = = mydb.cursor()
crsr.execute("SELECT * FROM employee")
recrds = crsr.fetchall()
for rws in recrds:
print(rws)
SELECT specific columns
SELECT name, address FROM employee
import mysql.connector
db = mysql.connector.connect(
host="localhost", user="username", passwd="password", database="dbname"
)
crsr = = mydb.cursor()
crsr.execute("SELECT name, address FROM employee")
recrds = crsr.fetchall()
for rws in recrds:
print(rws)
Get records on condition basis (where clause)
where clause का उपयोग कर condition के आधार पर table से records को लाया जा सकता है।
import mysql.connector
db = mysql.connector.connect(
host="localhost", user="username", passwd="password", database="dbname"
)
crsr = = mydb.cursor()
crsr.execute("SELECT name, address FROM employee WHERE id=1")
recrds = crsr.fetchall()
for rws in recrds:
print(rws)
0 टिप्पणियाँ
If you have any doubt. Please let me know