
Learning SQL JOIN and Window Functions
SQL JOINS JOIN clause is used to combine rows from two or more tables, based on a related column between them To use joins we need to have a primary key and a foreign key A Primary Key - uniquely identifies each row in a table. It must contain unique values. Cannot contain NULL. Only one primary key per table (but it can be made of multiple columns – composite key) A Foreign Key is a column that references the Primary Key of another table. It creates a relationship between tables. Can contain duplicate values. Can sometimes contain NULL. Ensures referential integrity (you cannot reference a non-existing record) We are going to use the two below tables to explain the concept of join. select * from employees e; select * from departments d ; There are different types of JOINs in SQL: (INNER) JOIN : Returns only rows that have matching values in both tables select e.name, d.department_name from employees e inner join departments d on e.department_id = d.department_id; LEFT (OUTER) JOIN : R
Continue reading on Dev.to Tutorial
Opens in a new tab


