They are however, times when we want to restrict the query results to a specified condition. The WHERE clause in SQL comes handy in such situations.
WHERE clause Syntax
The basic syntax for the WHERE clause when used in a MySQL SELECT WHERE statement is as follows. HERE
“SELECT * FROM tableName” is the standard SELECT statement
“WHERE” is the keyword that restricts our select query result set and “condition” is the filter to be applied on the results. The filter could be a range, single value or sub query.
Let’s now look at a practical example. Suppose we want to get a member’s personal details from members table given the membership number 1, we would use the following script to achieve that. Executing the above script in MySQL workbench on the “myflixdb” would produce the following results.
WHERE clause combined with – AND LOGICAL Operator
The WHERE condition in MySQL when used together with the AND logical operator, is only executed if ALL filter criteria specified are met.
WHERE clause combined with – OR LOGICAL Operator
Executing the above script in MySQL workbench against the “myflixdb” produces the following results.
WHERE clause combined with – NOT IN Keyword
WHERE clause combined with – COMPARISON Operators
= Equal To
Greater than