The ‘WHERE’ clause in SELECT query can be used to constrain the selected records from the Database table.
The following operators can be used in the ‘WHERE’ clause of SELECT query.
Operator | Explanation |
EQ / = | The data of operand1 must be equal to operand2. |
NE / < > | The data of operand1 must not be equal to operand2. |
LT / < | The data of operand1 must be lesser than operand2. |
GT / > | The data of operand1 must be greater than operand2. |
LE / <= | The data of operand1 must be lesser than or equal to operand2. |
GE / >= | The data of operand1 must be greater than or equal to operand2. |
We can also use AND, OR conditions in the ‘WHERE’ clause.
SELECT contact_id contact_name FROM ztt_db_table2 INTO TABLE lt_contact WHERE contact_id = 102.
‘AND’ condition :
SELECT contact_id contact_name FROM ztt_db_table2 INTO TABLE lt_contact WHERE contact_id = 102 AND contact_name = ‘Tom’.
‘LIKE’ condition:
When we are not sure about the exact value to be used in the WHERE clause, then we can use the LIKE option to narrow down the records.
SELECT contact_id contact_name FROM ztt_db_table2 INTO TABLE lt_contact
WHERE contact_name LIKE ‘T_’.
The above ‘SELECT’ statement will select all the records with the contact_name starting with the letter ‘T’.