Mysql union help
Hi I have a query like that
SELECT column1,MAX(column2) AS MAX FROM table1 GROUP BY column1 ORDER BY MAX DESC;
and i have a second table which name table2 and has same column2 but different column1 name, I want to apply this query to union of these table,when i try this
开发者_JAVA技巧SELECT column1,MAX(column2) AS MAX FROM ((SELECT * FROM table1) union (SELECT * FROM table2)) GROUP BY column1 ORDER BY MAX DESC;
I got this error "ERROR 1248 (42000): Every derived table must have its own alias"
how can i do that? thanks for help...
The alias comes after the derived table definition,
SELECT column1,MAX(column2) AS MAX FROM
(SELECT * FROM table1 union SELECT * FROM table2) t3
GROUP BY column1 ORDER BY MAX DESC;
The alias is t3
精彩评论