Better way to select all columns from first table and only one column from second table on inner join

≡放荡痞女 提交于 2019-11-29 06:39:39

问题


Graphical Explaination

Table 1's columns:

|a|b|c|d|e|

Table 2's columns:

|a|x|y|z|

I want only a, b, c, d, e, x. I only want column a from table 1, not column a from table 2.

Wordy Explaination

I have two tables with one column sharing a common name. If I use a Select * and use an inner join, I get all the columns returned including two columns with the same name.

I want to select everything from the first table, and only one column from the second table. Right now I am specifing every single column I need, which is a drag. Is there an easier way to grab everything from the first table and only the one column I want from the second table?

Thanks in advance.


回答1:


you need to specify the column name of the second table if it has the same columnName with the other table, you need to supply an ALIAS on it,

SELECT  tb1.*, tb2.x
FROM    tableA tb1
        INNER JOIN tableB tb2
            ON tb1.a = tb2.a


来源:https://stackoverflow.com/questions/14000572/better-way-to-select-all-columns-from-first-table-and-only-one-column-from-secon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!