All pastes #44366 Raw Edit

Miscellany

public text v1 · immutable
#44366 ·published 2006-03-03 19:50 UTC
rendered paste body
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?