1.

Clauses in SQL

Answer»

Clauses are in-built functions available in SQL and are used for filtering and analysing data quickly allowing the user to efficiently extract the required information from the database.

The below table lists some of the important SQL clauses and their description with examples:

NameDescriptionExample
WHEREUsed to select data from the database based on some conditions.SELECT * from Employee WHERE age >= 18;
ANDUsed to combine 2 or more conditions and returns true if all the conditions are True.SELECT * from Employee WHERE age >= 18 AND salary >= 45000 ;
ORSimilar to AND but returns true if any of the conditions are True.Select * from Employee where salary >= 45000 OR age >= 18
LIKEUsed to search for a specified pattern in a column.SELECT * FROM Students WHERE Name LIKE ‘a%’;
LIMITPuts a restriction on how many rows are returned from a query.SELECT * FROM table1 LIMIT 3;
ORDER BYUsed to sort given data in Ascending or Descending order.SELECT * FROM student ORDER BY age ASC
GROUP BYGroups rows that have the same values into summary rows.SELECT COUNT(StudentID), State FROM Students GROUP BY State;
HAVINGIt performs the same as the WHERE clause but can also be used with aggregate functions.SELECT COUNT(ID), AGE FROM Students GROUP BY AGE HAVING COUNT(ID) > 5;



Discussion

No Comment Found