good UNION:
mysql> select count(me_id) as tot from salad where to_days(me_date)=to_days(now())
-> union select count(me_id) tot from salad where to_days(me_date)>to_days(now())-7
-> union select count(me_id) as tot from salad where to_days(me_date)>to_days(now())-30
-> union select count(me_id) as tot from salad where to_days(me_date)>to_days(now())-60
-> union select count(me_id) as tot from salad;
+-----+
| tot |
+-----+
| 0 |
| 4 |
| 12 |
| 14 |
| 15 |
+-----+
5 rows in set (0.00 sec)
bad UNION:
mysql> select count(me_id) as tot from areyouget where to_days(me_date)=to_days(now())
-> union select count(me_id) tot from areyouget where to_days(me_date)>to_days(now())-7
-> union select count(me_id) as tot from areyouget where to_days(me_date)>to_days(now())-30
-> union select count(me_id) as tot from areyouget where to_days(me_date)>to_days(now())-60
-> union select count(me_id) as tot from areyouget;
+-----+
| tot |
+-----+
| 1 |
| 2 |
+-----+
2 rows in set (0.00 sec)
Why is the second query only returning two rows? Each select alone returns a result - what's different between these two statements?