Question : MYSQL UNION RETURNS DUPLICATE DATES

I have a query:

"SELECT date FROM table1 WHERE exp_date >= '".date("Y-m-d")."' UNION ALL SELECT date FROM table2 WHERE WHERE exp_date >= '".date("Y-m-d")."' UNION ALL SELECT date AS thedate FROM table3 WHERE WHERE exp_date >= '".date("Y-m-d")."' UNION ALL SELECT date AS thedate FROM table4 WHERE WHERE exp_date >= '".date("Y-m-d")."' UNION ALL SELECT date AS thedate FROM table5 WHERE WHERE exp_date >= '".date("Y-m-d")."'  GROUP BY date ORDER BY date DESC"

Though I'm grouping by date it still returns for example:

july 14

July 14

July 13

July 12

July 12

How can I prevent this...Thanks

Answer : MYSQL UNION RETURNS DUPLICATE DATES

you'd have to put it all in a subquery:

SELECT * FROM
(SELECT date FROM table1 WHERE exp_date >= '".date("Y-m-d")."' UNION ALL SELECT date FROM table2 WHERE WHERE exp_date >= '".date("Y-m-d")."' UNION ALL SELECT date AS thedate FROM table3 WHERE WHERE exp_date >= '".date("Y-m-d")."' UNION ALL SELECT date AS thedate FROM table4 WHERE WHERE exp_date >= '".date("Y-m-d")."' UNION ALL SELECT date AS thedate FROM table5 WHERE WHERE exp_date >= '".date("Y-m-d")."'  GROUP BY date ORDER BY date DESC) t
GROUP "BY `date`
Random Solutions  
 
programming4us programming4us