Joins in SQL
Explore different join types to seamlessly merge data from multiple tables in your SQL queries.
45. INNER JOIN: Retrieves Records That Have Matching Values in Both Tables
SELECT * FROM employees
INNER JOIN departments ON employees.department_id = departments.department_id;
This query will retrieve records from both the employees and departments tables where there is a match on the department_id column.
46. LEFT JOIN: Retrieves All Records from the Left Table and the Matched Records from the Right Table
SELECT * FROM employees
LEFT JOIN departments ON employees.department_id = departments.department_id;
This query will retrieve all records from the employees table and only the matching records from the departments table.
47. RIGHT JOIN: Retrieves All Records from the Right Table and the Matched Records from the Left Table
SELECT * FROM employees
RIGHT JOIN departments ON employees.department_id = departments.department_id;
This query will retrieve all records from the departments table and only the matching records from the employees table.
48. FULL OUTER JOIN: Retrieves All Records When There Is a Match in Either the Left or Right Table
SELECT * FROM employees
FULL OUTER JOIN departments ON employees.department_id = departments.department_id;
This query will retrieve all records from both the employees and departments tables, including unmatched records.
49. CROSS JOIN: Retrieves the Cartesian Product of the Two Tables
SELECT * FROM employees
CROSS JOIN departments;
This query will retrieve all possible combinations of records from the employees and departments tables.
50. SELF JOIN: Joins a Table to Itself
SELECT e1.first_name, e2.first_name
FROM employees e1, employees e2
WHERE e1.employee_id = e2.manager_id;
In this example, the employees table is joined to itself to find employees and their respective managers based on the manager_id column.
SQL Cheat Sheet
In this article, we will explore the ultimate SQL cheat sheet with the PDF, covering a wide range of SQL commands, Joins in SQL, CRUD Operations, SQL Trigger, SQL Transactions, and advanced topics to help master SQL effectively.
SQL (Structured Query Language) is a Query language used for managing and manipulating relational databases databases. It allows users to interact with databases. SQL allows users to perform various tasks such as querying data, updating data, inserting new records, deleting records, creating and modifying database schemas, and managing permissions.
Table of Content
- Create a Database in SQL
- Creating Data in SQL
- Reading/Querying Data in SQL
- Updating/Manipulating Data in SQL
- Deleting Data in SQL
- Filtering Data in SQL
- SQL Operator
- Aggregation Data in SQL
- Constraints in SQL
- Joins in SQL
- SQL Functions
- Subqueries in SQL
- Views in SQL
- Indexes in SQL
- Transactions in SQL
- Advanced Mixed Data in SQL
- SQL Cheat Sheet PDF
Contact Us