I want to write SQL query which select some columns from the first table and all columns from the second table.
ID is the PK in table1 and id is the FK in table2.
Is this correct:
SELECT ID, table2.ALL
FROM table1
INNER JOIN table2 ON table1.ID = table2.id
WHERE table1.ID= x AND table1.Column3 = 'y'
Do you have a column called
ALLintable2or do you want to select all columns fromtable2??If you want all columns use
table2.*instead:Also, since you have
IDin both tables, you need to specify which one to select in your statement.Update: if you don’t want all columns from
table2, then you need to explicitly specify the columns that you do want: