1๏ธโฃ What is SQL?
SQL (Structured Query Language) is a standardized language used to manage and manipulate relational databases.
2๏ธโฃ Most Common SQL Commands:
โข SELECT โ fetch data
โข INSERT โ add data
โข UPDATE โ modify existing data
โข DELETE โ remove data
โข CREATE โ create a new table or database
โข DROP โ delete a table or database
3๏ธโฃ Filtering Data:
To filter records based on conditions:
SELECT * FROM employees WHERE salary > 50000;
4๏ธโฃ Sorting Data:
To sort results in ascending or descending order:
SELECT name FROM students ORDER BY marks DESC;
5๏ธโฃ Using Functions:
Common aggregate functions:
โข COUNT() โ counts the number of records
โข AVG() โ calculates the average value
โข MAX() / MIN() โ returns the highest/lowest value
โข SUM() โ computes the total sum
6๏ธโฃ Grouping Data:
To group records and perform calculations:
SELECT department, COUNT(*) FROM employees GROUP BY department;
7๏ธโฃ Joins:
Combining rows from two or more tables based on related columns:
โข INNER JOIN: Returns matching records in both tables
โข LEFT JOIN: Returns all records from the left table and matching records from the right table
โข RIGHT JOIN: Returns all records from the right table and matching records from the left table
โข FULL JOIN: Returns all records when there is a match in either left or right table
8๏ธโฃ Aliases:
To rename a column or table for readability:
SELECT name AS employee_name FROM employees;
9๏ธโฃ Subqueries:
Using a query within another query:
SELECT name FROM students WHERE marks > (SELECT AVG(marks) FROM students);
๐ Real Use Cases:
โข Managing employee records
โข Generating sales reports
โข Tracking inventory levels
โข Analyzing customer insights
๐ฌ Tap โค๏ธ for more SQL tips and tricks!