SQL Keys and Joining Tables Flashcards
What do PRIMARY KEY statements do?
provide a unique identifier for each row in a table
What is the basic PRIMARY KEY statement format?
CREATE TABLE table_name(column_name data_type PRIMARY KEY, column_name data_type…);
What is a foreign key?
a column that contains the primary key of another database
How do you specify a column that belongs to a specific table?
table_name.column_name
What do JOIN statements do?
combine two tables
What is an inner join?
combines two tables with all common values (i.e., ‘1,2,3,4’ corresponds to ‘1,2,3,4’
What is an outer join?
combines two tables with only SOME common values (i.e., ‘1,2,3,4’ joins with ‘1,2,5,6’)
What is the basic JOIN statement format?
SELECT * FROM table_name1 JOIN table_name2 ON table_name1.column_name = table_name2.column_name;
What is a LEFT or RIGHT join?
combine two tables in an outer join, but place ‘null’ values where items do not match
What do AS statements do?
rename a column with an “alias”, which can be useful when joining tables
What is the basic AS statement format?
table_name.column_name AS ‘alias’