Delete Query:

DELETE FROM employees where id=1;
SELECT * FROM employees;

image

Drop command:

DROP table employees;

image

Joins

Inner Join:

-- INNER JOIN: Matches records with a common department_id
SELECT e.name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.id;

image

Left Join:

-- LEFT JOIN: Includes all employees, even if they don't belong to a department
SELECT e.name, d.department_name
FROM employees e
LEFT JOIN departments d ON e.department_id = d.id;

image

Right Join:

-- RIGHT JOIN: Includes all departments, even if no employees belong to them
SELECT e.name, d.department_name
FROM employees e
RIGHT JOIN departments d ON e.department_id = d.id;

image

Full Outer Join:

-- FULL OUTER JOIN: Includes all employees and departments (Not supported in MySQL directly, use UNION)
SELECT e.name, d.department_name
FROM employees e
LEFT JOIN departments d ON e.department_id = d.id
UNION
SELECT e.name, d.department_name
FROM employees e
RIGHT JOIN departments d ON e.department_id = d.id;

image

Cross Join:

-- CROSS JOIN: Matches each employee with every department
SELECT e.name, d.department_name
FROM employees e
CROSS JOIN departments d;

image