SQL clause is the specific part of a SQL statement which is used to perform various operations. It can be combined to create more complex queries to retrieve and manipulate data.
WHERE clause is used to specify condition(s) to filter data in the database. It is often used with other clauses such as 'SELECT', 'FROM' and 'ORDER BY' etc. to retrieve, specify table, sort and manipulate data.
SELECT column_name(s) FROM table_name WHERE conditions;
• Specify the column(s) name after the 'SELECT' keyword.
• Specify Asterisk (*) symbol to selects all columns from the table after the 'SELECT' keyword.
• Specify the table name after the 'FROM' keyword.
• Specify the conditions after the 'WHERE' keyword.
1. Suppose we have a table called [Employee] table with gender column containing male and female values.
2. Let's retrieve data from the [Employees] table where the gender is male.
3. Run below SQL statement :
SELECT * FROM [Employees] WHERE Gender = 'Male' ;
4. Above statement will select the data from the [Employees] table where the gender is male.
That's it! You have successfully retrieved the data from [Employees] table where the gender is male.
The WHERE clause in SQL is used to filter records based on specified conditions.
To use 2 conditions in the WHERE clause in SQL, you can combine them using logical operators such as AND or OR.
The WHERE clause is used to filter rows before grouping in SQL, while the HAVING clause is used to filter groups after grouping.
Clauses in SQL are components of a query that specify criteria for the retrieval or manipulation of data, such as SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY.