0% found this document useful (0 votes)
57 views2 pages

SQL Multiple Tables

Uploaded by

Vlad Neagu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
57 views2 pages

SQL Multiple Tables

Uploaded by

Vlad Neagu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 2
Cheatsheets / Learn SQL Multiple Tables Outer Join ‘An outer join wll combine rows from different tables even ifthe join condition is not met. Ina LEFT JOIN , every row in the left table is returned in the result set, and if the join condition is not met, then NULL. values are used to fil in the columns from the right table, WITH Clause The WITH clause stores the result of a query in a ‘temporary table ( temporary_movies ) using an alias, Multiple temporary tables can be defined with one Instance of the WITH keyword. UNION Clause Tne UNION clause is used to combine results that appear trom multiple SELECT statements and fiter duplicates, For example, given first_names table wth @ column name containing rows of data “James” and “Hermione”, and a last_names table with a column name containing rows of data “James", “Hermione” and "Cassidy", the result of this query would contain three name s: "Cassidy", “James”, and "Hermione”. CROSS JOIN Clause Tne CROSS JOIN clause is used to combine each row from one table with each row from another in the result set. This JOIN is helpful for creating all possible combinations forthe records (rows in two tables, The glven query will select the shirt_eolor and pants_color columns from the result set, which wil contain all combinations of combining the rows inthe shirts and pants tables. If there are 3 diferent shirt colors in the shirts table and §aitferent pants colors inthe pants table then the resuit st will contain 3x5 =15 rows [codelcacemy Foreign Key ‘A foreign key isa reference in one table's records to the primary key of another table. To maintain muttiple records for a specific row, the use of foreign key plays @ Bo Pu vital role. For instance, to track al the orders of a 1 ‘Abby Caren specific customer, the table order (illustrated at the 2 ‘Aaron Paul bottom of the image) can contain a foreign key. 3 Gratin Joseph 2 1 Primary Key A primary key column in a SOL table i used to uniguely identity each recordin that table. primary key cannot fname name be NULL Inthe example, customer id isthe primary key. The same value cannot re-occur in a a ey ay primary key column, Primary keys are often used in 2 Aaron Paul JOIN operations. 3 Sean ar Inner Join ‘The JOIN clause allows for the return of results from ‘more than one table by joining them together with other results based on common column values specified using an ON clause. INNER JOIN is the default JOIN and it will only return results matching ON = : the condition specified by ON L Print 69 Share ¥

You might also like