Hello Everyone,
How are you, I hope you guys will happy and well. By the grace of God, I am also well. Today I am here with new post of SQL and PL/SQL series in which i am going to discuss SQL operators that will used in where clause.
Different SQL operators are mentioned below.
- LIKE
- IN
- BETWEEN
LIKE OPERATOR
First of all, we discuss about the LIKE operator, why we use it in SQL and how much worth it have in report building. LIKE operator are used to search data from a column for a specified pattern. The percent % sign is used with like operator to find the specific type of data.
For example, I have a table with multiple rows and columns. I want to filter out the data using like operator.
No | sector | cust_id | name_1 | Town |
---|---|---|---|---|
1 | 1000 | 4270603 | SIKANDAR | PESHAWAR |
2 | 1000 | 4270939 | ALI TARIQ | ALI PUR |
3 | 1000 | 5715170 | ALI HAMZA | GALA YOUSAF |
4 | 1000 | 7796882 | IMRAN | KHANEWAL |
5 | 1000 | 953045 | UMAR | YAZMAN |
Now we use the LIKE operator then see the result
select sector , cust_id , name_1 , Town from users where name_1 LIKE '%ALI%'
I am applying the LIKE operator on name_1 column to filter out those data rows who have "ALI" name. it does not meter where it exists in the data of column. To filter out data rows where the name contains "ALI" in the name_1 column regardless of its position within the data, we will use the '%' wildcard on both sides of "ALI" within the LIKE operator.
No | sector | cust_id | name_1 | Town |
---|---|---|---|---|
1 | 1000 | 4270939 | ALI TARIQ | ALI PUR |
2 | 1000 | 5715170 | ALI HAMZA | GALA YOUSAF |
In the above result. we can see that it selects all rows where the name_1 column contains "ALI" anywhere within its data.
IN OPERATOR
IN Operator is used to perform the specific operation by using multiple filters in where clause. basically, it fulfils the OR operator operations. It allows us to specify a list of values that we want to match against any subjected column.
For example, we want to filter out those data whose cust_id is equal to (5715170 , 4270939 ).
select * from users where cust_id in ('5715170 ' , '4270939' ) ;
No | sector | cust_id | name_1 | Town |
---|---|---|---|---|
1 | 1000 | 4270939 | ALI TARIQ | ALI PUR |
2 | 1000 | 5715170 | ALI HAMZA | GALA YOUSAF |
BETWEEN OPERATOR
BETWEEN operator is commonly used to filter data within a specific range, especially when dealing with date or timestamp data types. It is the best way to query for records that fall within a particular period or interval. By specifying the start and end points of the range, we can easily retrieve data that meets our criteria without needing to construct complex conditions manually.
SELECT * FROM tables WHERE date BETWEEN '10-JAN-24' AND '20-JAN-24';
It would be my pleasure if you will share your opinion and reviews on this topic
Please cast witness vote to @bangla.Witness or set proxy to @rme.
_
Vote @bangla.witness as witness
Set Proxy @rme as proxy
Special Thanks.
Cc: @rme
Cc: @hungry-griffin
Cc: @steemcurator02
Thanks for giving your precious time to my post.
Follow | Upvote | Share | Comments
Follow me on Instagram.
Instagram
🆃🅷🅰️🅽🅺 🆈🅾️🆄