I am trying to do something like this:
SELECT a.date AS EnrollDate, a.id, a.name, b.address FROM student a JOIN Location b ON a.id=b.id UNION SELECT a.date AS EnrollDate, a.id, a.name, b.address FROM teacher a JOIN Location b ON a.id=b.id WHERE a.date>'2010-01-01' ORDER BY EnrollDate
But the WHERE clause applies only to the second SELECT statement. I need to apply SELECT somehow. The only option I have now is to apply the WHERE clause individually. But I work with several UNIONs, and it's pretty tedious to include WHERE in all places. I was wondering if there is a simple way out.
By the way, I work with MySQL.
sql mysql
jitendra
source share