Verwenden von Union All und Order By in MySQL
Ich habe 2 Tische:
create table advertised_products(id int,title varchar(99),timestamp timestamp);
insert advertised_products select 1,'t1',curdate();
create table wanted_products(id int,title varchar(99),timestamp timestamp);
insert wanted_products select 1,'t1',now();
Ich benutze diese Abfrage, um die Datensätze zu erhalten:
(
SELECT
ap.*,
'advertised' as type
FROM advertised_products as ap
)
union all
(
SELECT
wp.*,
'wanted' as type
FROM wanted_products as wp
)
ORDER BY timestamp desc limit 3
Aber es gibt Fehler:
Die Spalte 'timestamp' in der order-Klausel ist nicht eindeutig
Wie kann ich das sortieren?