What is the WHERE clause in SQL?
The WHERE clause in SQL filters the rows returned by a SELECT, UPDATE, or DELETE statement based on certain conditions. The WHERE clause specifies a condition that each row must meet to be returned or affected by a query.
The basic syntax of a WHERE clause is:
SELECT column_name(s) FROM table_name WHERE condition;
Here, the condition is a boolean expression evaluated for each row in the table. If the expression evaluates to TRUE, the row is included in the result set; otherwise, it is excluded.
The condition can be a comparison between columns and values, a pattern match, or a combination of multiple conditions using logical operators such as AND and OR.
For example, the following query returns all columns and rows from the tv_show table where the GENRE column exactly matches ‘Thriller’.
SELECT * FROM SANDBOX.tv_show WHERE GENRE = 'Thriller';