SQL post
SQL post
Command Description
CREATE Creates a new table, a view of a table, or other object in the database.
DROP Deletes an entire table, a view of a table, or other objects in the database
Command Description
Command Description
SQL Uses in Finance: Organizations often store financial data in databases since they are highly
secure and can be queried easily. Finance professionals can extract this data to make data-driven
decisions.
SQL Uses in Healthcare: SQL is often used to manipulate and analyze patient
information stored in clinical databases.
PRACTISE EXERCISES:
Beginner Level:
Write a query to retrieve all the columns from a table named employees.
Retrieve the names of employees from the employees table who work in the "Sales" department.
Display all product details from the products table sorted by price in descending order.
Find the total number of employees in the employees’ table.
Count the number of employees in each department.
Intermediate Level:
Retrieve the names of employees and the names of their respective managers from the employees
table and managers’ table.
Find the names of employees earning a salary higher than the average salary in the company.
Increase the salary of employees in the "IT" department by 10%.
Remove employees who have not been active since 2020.
Write a query to categorize employees into "High", "Medium", and "Low" salary bands.
Advanced Level:
Rank employees based on their salaries within each department.
List all customers who placed orders in the last month, along with the total amount spent.
Find the second-highest salary in the employees table using a CTE.
Knowledge Check:
1. Which SQL query retrieves data from a table and sorts it in descending order by a column named age?
A) SELECT * FROM students ORDER BY age;
B) SELECT * FROM students SORT DESC age;
C) SELECT * FROM students ORDER BY age DESC;
D) SELECT * FROM students SORTED BY age DESC;
2. Which of the following is NOT an aggregate function in SQL?
A) COUNT()
B) SUM()
C) AVG()
D) WHERE
3. Which type of JOIN returns all records from both tables, including unmatched rows?
A) INNER JOIN
B) LEFT JOIN
C) RIGHT JOIN
D) FULL OUTER JOIN
4. Which SQL constraint is used to ensure that all values in a column are unique?
A) PRIMARY KEY
B) FOREIGN KEY
C) UNIQUE
D) NOT NULL
5. Which SQL statement is used to delete a record from a table?
A) REMOVE FROM
B) DELETE FROM
C) DROP
D) TRUNCATE
Further Reading/Resources:
PostgreSQL: PostgreSQL is a powerful, open-source object-relational database system with over 35
years of active development that has earned it a strong reputation for reliability, feature robustness, and
performance.
https://www.postgresql.org/download/
SQL tutorial:
https://www.geeksforgeeks.org/sql-tutorial/