SQL_Topic_Wise_Notes_HackerRank
SQL_Topic_Wise_Notes_HackerRank
Certifications
1. SELECT Statements
The SELECT statement is used to retrieve data from a database. Basic structure:
SELECT column1, column2 FROM table_name;
2. WHERE Clause
Used to filter records. It extracts only those records that fulfill a specified condition.
SELECT * FROM employees WHERE salary > 50000;
3. DISTINCT Keyword
Removes duplicate values from the result.
SELECT DISTINCT department FROM employees;
4. ORDER BY (ASC/DESC)
Sorts the result set in ascending (default) or descending order.
SELECT * FROM employees ORDER BY salary DESC;
7. Aggregate Functions
COUNT(), SUM(), AVG(), MIN(), MAX() are used with GROUP BY to perform operations on
groups.
SELECT department, AVG(salary) FROM employees GROUP BY department;
SELECT e.name, d.name FROM employees e INNER JOIN departments d ON e.dept_id = d.id;
10. Subqueries
A subquery is a query nested inside another query.
SELECT name FROM employees WHERE dept_id = (SELECT id FROM departments WHERE
name = 'Sales');
17. Views
A virtual table based on SQL query.
CREATE VIEW SalesDept AS SELECT * FROM employees WHERE department = 'Sales';