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.
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.
The WHERE clause filters records based on specified conditions.
SELECT * FROM Employees WHERE age > 30;
The ORDER BY clause sorts the results in ascending or descending order.
SELECT * FROM Employees ORDER BY name ASC;
The GROUP BY clause groups rows that have the same values into summary rows.
SELECT department, SUM(salary) FROM Employees GROUP BY department;
The HAVING clause filters groups created by GROUP BY.
SELECT department, SUM(salary) FROM Employees GROUP BY department HAVING SUM(salary) > 100000;
The LIMIT clause limits the number of records returned in a query.
SELECT * FROM Employees LIMIT 5;
Using the LIMIT clause and filtering with WHERE helps improve query performance, especially when dealing with large datasets.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!