SQL Tutorial



DQL IN SQL


DQL in SQL

Data Query Language (DQL) is used to query or retrieve data from databases. The most common DQL command is SELECT, which is used for fetching records from one or more tables.

SELECT Statement

The SELECT statement is used to retrieve data from a table.

SELECT column1, column2 FROM table_name;

Example: SELECT * FROM Employees; fetches all columns from the Employees table.

WHERE Clause

The WHERE clause filters records based on specified conditions.

SELECT * FROM Employees WHERE age > 30;

ORDER BY Clause

The ORDER BY clause sorts the results in ascending or descending order.

SELECT * FROM Employees ORDER BY name ASC;

GROUP BY Clause

The GROUP BY clause groups rows that have the same values into summary rows.

SELECT department, SUM(salary) FROM Employees GROUP BY department;

HAVING Clause

The HAVING clause filters groups created by GROUP BY.

SELECT department, SUM(salary) FROM Employees GROUP BY department HAVING SUM(salary) > 100000;

LIMIT Clause

The LIMIT clause limits the number of records returned in a query.

SELECT * FROM Employees LIMIT 5;

Tip

Using the LIMIT clause and filtering with WHERE helps improve query performance, especially when dealing with large datasets.


🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review