SQL - Where
The where clause sets a conditional statement for your queries. Your server will query the database searching for rows that meet your specific where condition. A typical query will have the following syntax.
A conditional statement has 2 parts, the left side is your table column and the right side is the condition to be met. Example:WHERE table_column(s) = condition.
SQL Code:
SELECT * FROM employees WHERE Title = 'crew' ORDER BY Lastname;
SQL Table:
| ID | Lastname | Firstname | Title |
| 10 | Harris | Joel | crew |
| 9 | Hicks | Freddy | crew |
| 2 | Hively | Jessica | crew |
| 1 | Johnson | David | crew |
All the known typical operators can be used in the conditional statements, for a complete list backtrack to SQL Operators
SQL - Where multiple conditionals
SQL also supports multiple conditional statements within one script by using the AND or OR operators. Continuing the example from above we can select only those employees that worked 36 or more hours for the week, perhaps meaning they are full time employees.
SQL Code:
SELECT employees.Lastname,
employees.Firstname,
employees.Title,
payroll.Hours
FROM employees,payroll
WHERE employees.Lastname = payroll.Lastname
AND payroll.Hours => '36'
ORDER BY employees.Lastname;
As you can see, the where clause is a very powerful tool used to quickly pull rows from one table or many.
|