SQL
5. CROSS JOIN

CROSS JOIN: Returns the Cartesian product of both tables, meaning every row in the first table is combined with every row in the second table.

Syntax:

SELECT columns
FROM table1
CROSS JOIN table2;

Example:

SELECT employees.first_name, employees.last_name, departments.department_name
FROM employees
CROSS JOIN departments;

Example Table Creation and Joins
1. Create the employees table:

CREATE TABLE employees (
    employee_id INT PRIMARY KEY AUTO_INCREMENT,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    department_id INT
);

2. Create the departments table:

CREATE TABLE departments (
    department_id INT PRIMARY KEY AUTO_INCREMENT,
    department_name VARCHAR(50)
);

3. Insert sample data into the employees table:

INSERT INTO employees (first_name, last_name, department_id)
VALUES 
('John', 'Doe', 1),
('Jane', 'Smith', 2),
('Alice', 'Johnson', 1),
('Bob', 'Brown', 3);

4. Insert sample data into the departments table:

INSERT INTO departments (department_name)
VALUES 
('Engineering'),
('Marketing'),
('HR');

Performing Joins
CROSS JOIN Example:

SELECT e.first_name, e.last_name, d.department_name
FROM employees e
CROSS JOIN departments d;