I am trying to combine these two tables then order it by one column (stamp), and aliasing the second table’s id field. I’ve tried joins, merges, but nothing seems to work. I am also trying to group them by the mm
Table note
id | mm | stamp |
==========================
1 | 5 | 2009-12-11 |
2 | 33 | 2010-09-10 |
3 | 22 | 2011-07-08 |
4 | 1 | 2012-05-06 |
Table note_admin
id | mm | stamp |
==========================
1 | 5 | 2009-08-15 |
2 | 5 | 2011-11-11 |
3 | 5 | 2012-01-08 |
4 | 35 | 2012-02-06 |
Query I thought would work:
(SELECT * FROM note WHERE mm=5)
UNION
(SELECT id AS a_id, mm, stamp FROM note_admin WHERE mm=5)
ORDER BY stamp DESC
Expected Result
id | a_id | mm | stamp |
================================
| 3 | 5 | 2012-01-08 |
| 2 | 5 | 2011-11-11 |
1 | | 5 | 2009-12-11 |
| 1 | 5 | 2009-08-15 |
I don’t even know if this is possible. I found a way to sort this in PHP but it would be much easier if it can be done in mySQL. Thanks.
I think you mean this, note the same 4 column names (not sure about the order by though):