
Mastering Joins and Window Functions in SQL
Joins in SQL Joins allow one to combine rows from two or more tables based a related column. This is important when data is stored across multiple tables. There are several types of joins: a.INNER JOIN -Returns only the matching rows from both tables. Syntax SELECT columns FROM table1 INNER JOIN table2 ON table1.common_column = table2.common_column; Example SELECT c.customer_id, c.first_name, o.order_id,o.quantity FROM customers AS C INNER JOIN orders AS O ON c.customer_id = o.customer_id; This displays only customers who have placed an order. b.LEFT JOIN (LEFT OUTER JOIN) -Returns all rows from the left table and only matching rows from the right table. -If there's no match, NULL is returned on the right table columns. Syntax SELECT columns FROM table1 LEFT JOIN table2 ON table1.common_column = table2.common_column; Example SELECT c.customer_id, c.first_name, o.order_id, o.quantity FROM customers AS C LEFT JOIN orders AS O ON c.customer_id = o.customer_id; This displays all customers
Continue reading on Dev.to Tutorial
Opens in a new tab


