开发者

Mysql union help

开发者 https://www.devze.com 2023-02-26 05:31 出处:网络
Hi I have a query like that SELECT column1,MAX(column2) AS MAX FROM table1 GROUP BY column1 ORDER BY MAX

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

SELECT column1,MAX(column2) AS MAX FROM ((SELECT * FROM table1) union (SELECT * FROM table2)) GROUP BY column1 ORDER BY MAX DESC;

开发者_JAVA技巧

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号