开发者

MySQL: SELECT * FROM table1, table2.... column1 AS newColumnName

开发者 https://www.devze.com 2023-02-07 07:15 出处:网络
I\'m selecting data from two tables. And both of those tables have an ID column, and i need both of the ID columns returned after executing the Query. Is there any way to change the name of the ID col

I'm selecting data from two tables. And both of those tables have an ID column, and i need both of the ID columns returned after executing the Query. Is there any way to change the name of the ID column (from the second table i'm selecting from) to something else using AS?

I'm thinking something like this:

SELECT * FROM table1, table2 WHERE tabl开发者_高级运维e2.id AS newAlias

Can I use the WHERE statement like that?


You need to specify the alias for the column in the select list. e.g:

SELECT a.id AS table1_id, b.id AS table2_id, ....
  FROM table1 a, table2 b
 WHERE <YOUR CRITERIA>


@qwerty

You can write:

SELECT a.*,a.id AS table1_id, b.*,b.id AS table2_id, ....
FROM table1 a, table2 b
WHERE <YOUR CRITERIA>
0

精彩评论

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