Question

Select only some columns from a table on a JOIN

Is it possible to select only some columns from a table on a JOIN? (Any kind.)

 45  111802  45
1 Jan 1970

Solution

 60

Of course. Just list the columns you want to select as you would in any query:

SELECT table1.column1, table1.column2, table2.column3
FROM table1
LEFT JOIN table2 ON (...)

Note that I've included the table1. or table2. prefix on all columns to be sure there aren't any ambiguities where fields with the same name exist in both tables.

2009-08-25

Solution

 58

Add a * to just that table in your select statement, separate from other columns with a comma:

SELECT table1.*, table2.col2, table2.col3
FROM table1
LEFT JOIN table2
ON...

Source: https://stackoverflow.com/a/3492919/3417198

2019-11-12