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

Graphical explanation

Table 1:

|a|b|c|d|e| 

Table 2:

 |a|x|y|z| 

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

Wordy explanation

I have two tables with one column with a common name. If I use Select * and use the inner join, I get all the returned columns, 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 setting every column that I need, which is a drag and drop. Is there an easier way to grab everything from the first table and only one column that I want from the second table?

Thanks in advance.

+11
sql join inner-join mysql
source share
1 answer

you need to specify the column name of the second table, if it has the same column name with another table, you need to specify ALIAS ,

 SELECT tb1.*, tb2.x FROM tableA tb1 INNER JOIN tableB tb2 ON tb1.a = tb2.a 
+24
source share

All Articles