I wrote the code in MY SQL
SELECT *
FROM employees w,
employees m
WHERE w.manager_id = m.emp_id
AND w.salary> m.salary;
My question is how will I execute the same question using Python?
I wrote the code in MY SQL
SELECT *
FROM employees w,
employees m
WHERE w.manager_id = m.emp_id
AND w.salary> m.salary;
My question is how will I execute the same question using Python?
import mysql.connector as ms
mycon = ms.connect(host = "<localhostmostly>", user = "<yourusernameinSQL>", passwd = "<yourpwd>", database = "<yourdbname>")
mycursor = mycon.cursor()
query = '''SELECT *
FROM employees w,
employees m
WHERE w.manager_id = m.emp_id
AND w.salary> m.salary;'''
mycursor.execute(query)
This is the solution to your problem. If you want to print the results in Python, then write this line after the previously written code.
myresult = mycursor.fetchall()
print(myresult)
Hope this solved your problem! If you are writing the query in Python in a single line, do not use triple quotes (you will mostly be knowing that, but I thought I should say).