β SQL Basics You Should Know
Essential SQL fundamentals for beginners and interview preparation π»π
1οΈβ£ What is SQL?
SQL (Structured Query Language) is a standard language used to store, retrieve, update, and manage data in relational database systems such as MySQL, PostgreSQL, SQL Server, and Oracle.
2οΈβ£ Most Common SQL Commands
- SELECT β Fetch data from a table
- INSERT β Add new data
- UPDATE β Modify existing data
- DELETE β Remove data
- CREATE β Create tables or databases
- DROP β Delete tables or databases
3οΈβ£ Filtering Data
Use the WHERE clause to filter records based on specific conditions.
SELECT *
FROM employees
WHERE salary > 50000;
4οΈβ£ Sorting Data
Use ORDER BY to sort results in ascending (ASC) or descending (DESC) order.
SELECT name
FROM students
ORDER BY marks DESC;
5οΈβ£ Using Functions
Aggregate functions perform calculations on multiple rows.
- COUNT() β Counts number of records
- AVG() β Calculates average value
- MAX() / MIN() β Finds highest / lowest value
- SUM() β Calculates total sum
6οΈβ£ Grouping Data
GROUP BY is used with aggregate functions to group records.
SELECT department, COUNT(*)
FROM employees
GROUP BY department;
7οΈβ£ Joins
Joins combine rows from multiple tables using related columns.
- INNER JOIN β Matching records in both tables
- LEFT JOIN β All records from left table + matches
- RIGHT JOIN β All records from right table + matches
- FULL JOIN β All records from both tables
8οΈβ£ Aliases
Aliases improve readability by renaming columns or tables temporarily.
SELECT name AS employee_name
FROM employees;
9οΈβ£ Subqueries
A subquery is a query nested inside another query.
SELECT name
FROM students
WHERE marks > (SELECT AVG(marks) FROM students);
π Real-World Use Cases
- Managing employee records
- Generating sales and financial reports
- Tracking inventory levels
- Analyzing customer behavior and insights
Comments (0)
No comments yet
Be the first to share your thoughts!
Leave a Comment