mycursor = mydb.cursor()
sql = "SELECT \ users.name AS user, \
products.name AS favorite \
FROM users \
INNER JOIN products ON users.fav = products.id"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
print(x)
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Prevent SQL Injection :
prevent SQL injections, which is a common web hacking technique to destroy your database import mysql.connector .
Python MySQL Join :
users:
{ id: 1, name: 'rohan', fav: 154},
{ id: 2, name: 'prakash', fav: 154},
{ id: 3, name: 'Arti', fav: 155},
{ id: 4, name: 'Aditya', fav:},
{ id: 5, name: 'Vishal', fav:}
Products :
{ id: 154, name: 'Chocolate Heaven' },{ id: 155, name: 'Tasty Lemons' },
{ id: 156, name: 'Vanilla Dreams' }