DEV Community

Punitha
Punitha

Posted on

SQL Clauses

What are SQL Clauses?

SQL clauses are used to filter, sort, group, and organize query results.

  • WHERE

  • ORDER BY

  • GROUP BY

  • HAVING

WHERE Clause

  • The WHERE clause filters records based on a condition.
SELECT *
FROM Employee
WHERE Salary > 50000;
Enter fullscreen mode Exit fullscreen mode

ORDER BY Clause

  • The ORDER BY clause sorts the result in ascending or descending order.
SELECT *
FROM Employee
ORDER BY Salary DESC;
Enter fullscreen mode Exit fullscreen mode

GROUP BY Clause

  • The GROUP BY clause groups rows that have the same values.
SELECT Department, COUNT(*)
FROM Employee
GROUP BY Department;
Enter fullscreen mode Exit fullscreen mode

HAVING Clause

  • The HAVING clause filters grouped data.
SELECT Department, COUNT(*)
FROM Employee
GROUP BY Department
HAVING COUNT(*) > 5;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)