When making a join (inner, left outer, right outer or whatever), how can I specify which columns on the table to join into the original table?
Consider the following example:
SELECT FirstName FROM User LEFT OUTER JOIN Provider ON User.ProviderID = Provider.ID
This would select FirstName from user, but select everything from Provider. How can I specify which parts of Provider should be included in the resultset?
Just list the columns you want to select as you would in any query: SELECT table1. column1, table1. column2, table2.
The INNER JOIN selects all rows from both participating tables as long as there is a match between the columns. An SQL INNER JOIN is same as JOIN clause, combining rows from two or more tables. SELECT * FROM table1 JOIN table2 ON table1. column_name = table2.
If you want to select only specific columns, replace the * with the names of the columns, separated by commas. The following statement selects just the name_id, firstname and lastname fields from the master_name table.
Using the “FROM Table1, Table2” Syntax One way to join two tables without a common column is to use an obsolete syntax for joining tables. With this syntax, we simply list the tables that we want to join in the FROM clause then use a WHERE clause to add joining conditions if necessary.
This will only include User.FirstName
and Provider.ProviderID
in the final resultset:
SELECT User.FirstName, Provider.ProviderID FROM User LEFT OUTER JOIN Provider ON User.ProviderID = Provider.ID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With