Which operator is used in a WHERE clause?
WHERE keyword is used for fetching filtered data in a result set. Show
Basic Syntax: SELECT column1,column2 FROM table_name WHERE column_name operator value; column1 , column2: fields int the table table_name: name of table column_name: name of field used for filtering the data operator: operation to be considered for filtering value: exact value or pattern to get related data in result List of operators that can be used with where clause:
Queries
SELECT * FROM Student WHERE Age=20;
SELECT ROLL_NO,NAME,ADDRESS FROM Student WHERE ROLL_NO > 3;
BETWEEN operator It is used to fetch filtered data in a given range inclusive of two values. Basic Syntax: SELECT column1,column2 FROM table_name WHERE column_name BETWEEN value1 AND value2; BETWEEN: operator name value1 AND value2: exact value from value1 to value2 to get related data in result set. Queries
SELECT * FROM Student WHERE ROLL_NO BETWEEN 1 AND 3;
SELECT NAME,ADDRESS FROM Student WHERE Age BETWEEN 20 AND 30;
LIKE operator It is used to fetch filtered data by searching for a particular pattern in where clause. Basic Syntax: SELECT column1,column2 FROM table_name WHERE column_name LIKE pattern; LIKE: operator name pattern: exact value extracted from the pattern to get related data in result set. Note: The character(s) in pattern are case sensitive. Queries
SELECT * FROM Student WHERE NAME LIKE 'S%';
SELECT * FROM Student WHERE NAME LIKE '%AM%';
IN operator It is used to fetch filtered data same as fetched by ‘=’ operator just the difference is that here we can specify multiple values for which we can get the result set. Basic Syntax: SELECT column1,column2 FROM table_name WHERE column_name IN (value1,value2,..); IN: operator name value1,value2,..: exact value matching the values given and get related data in result set. Queries
SELECT NAME,ADDRESS FROM Student WHERE Age IN (18,20);
SELECT * FROM Student WHERE ROLL_NO IN (1,4);
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. Can we use operator in WHERE clause in SQL?The SQL IN Operator
The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.
What is a WHERE clause in SQL?In a SQL statement, the WHERE clause specifies criteria that field values must meet for the records that contain the values to be included in the query results.
Which operator Cannot be used in WHERE clause?Join, subquery and aggregate functions are not supported.
Which conditions can we use with WHERE clause?The SQL WHERE clause is used to specify a condition while fetching the data from a single table or by joining with multiple tables. If the given condition is satisfied, then only it returns a specific value from the table. You should use the WHERE clause to filter the records and fetching only the necessary records.
|