When retrieving data from a single table or by joining data from multiple tables, a condition is specified using the SQL WHERE clause. If the given condition is satisfied, then only it returns a specific value from the table. The WHERE clause should be used to filter the records and only retrieve those that are required.
Syntax:
SELECT column_names
FROM table_name
WHERE conditions;
The SELECT
clause specifies the columns to be returned from the table(s), the WHERE
clause contains the conditions that must evaluate to true for a row to be returned as a result.
Operator | Description |
---|---|
> | Greater Than |
>= | Greater than or Equal to |
< | Less Than |
<= | Less than or Equal to |
= | Equal to |
<> | Not Equal to |
BETWEEN | In an inclusive Range |
LIKE | Search for a pattern |
IN | To specify multiple possible values for a column |
Consider the PRODUCTS table having the following records −
ID | ITEM | QUANTITY | PRICE_PER_ITEM |
1 | Chair | 67 | 850.00 |
2 | Ball | 12 | 600.00 |
3 | Jars | 9 | 500.00 |
SELECT ID,
ITEM,
QUANTITY,
PRICE_PER_ITEM
FROM PRODUCTS WHERE ID = 3;
Output:
ID | ITEM | QUANTITY | PRICE_PER_ITEM |
3 | Jars | 9 | 500.00 |
SELECT ID,
ITEM,
QUANTITY
FROM PRODUCTS WHERE PRICE_PER_ITEM > 500.00;
Output:
ID | ITEM | QUANTITY |
1 | Chair | 67 |
2 | Ball | 12 |
SELECT ID,ITEM,PRICE_PER_ITEM
FROM PRODUCTS WHERE ITEM = "Chair";
Output:
ID | ITEM | PRICE_PER_ITEM |
1 | Chair | 850.00 |
Note: multiple conditions in the where clause can be used as per the requirements.
Note: also read about DCL Commands: GRANT and REVOKE
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
Build an autocomplete system that, given a query string s and a set of possible…
Design a job scheduler that accepts a function f and an integer n. The scheduler…
Problem Statement (Asked By Airbnb) Given a list of integers, write a function to compute…