This is the code about UNION QUERY:
smith ='Smith'smithb='Smith'sql="""SELECT Distinct Pnumber FROM PROJECT, DEPARTMENT, EMPLOYEE WHERE Dnum = Dnumber AND Mgr_ssn=Ssn AND Lname= %s UNION SELECT Distinct Pnumber PROJECT, WORKS_ON, EMPLOYERE WHERE Pnumber =Pno AND Essn=Ssn AND Lname=%s"""curs.execute(sql,(smith,smithb))#curs.execute(sql2,('Smith'))conn.commit() rows = curs.fetchall()print(rows)
This is the err message!!:
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE Pnumber =Pno AND Essn=Ssn AND Lname='Smith'' at line 1")
I need to know the pymysql union query syntax.Thank you.