开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜