Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Select Record python MySQL (python class part 👉 36)in Hindi

 

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)

Python class part 👉 36

Go to next class part 👉 37


एक टिप्पणी भेजें

0 टिप्पणियाँ