SQL WHERE clause is an optional clause used to define what records are to be included in the query. We use conditional operators like <, >, =, >=, <=, !=(<>) , BETWEEN a AND b, IN(list) etc.
- SELECT <field>,<field>
- FROM <table_name>
- WHERE <field> <operator> <value>;
For example we have a table Employee:
Now, if we want to select the first name and employee_id of only the ones who are males:
- SELECT Employee_id, First_name
- FROM Employee
- WHERE sex = ‘male’;
This will give the following result:
For strings , we always enclose them in single quotes.