like & wild card operator SQL

like/wild card :- LIKE operator is used to search/compare string pattern. this keyword is used with where clause. to check string pattern, two special operators percentage (%) and underscore (_) can used with like keyword. it collectively called wild card.

a. percentage (%) :- it represents one or more strings of character, in which value of character is randomly.

b. underscore (_) :- it represents only one string of character, in which value of character is randomly.

Syntax :- select column_name  from table_name where column_name like "string pattern";

sells table -
Order ID
Order price
Quantity
Cust_name
1
100
2
Aayush
2
65
4
Tarun
3
287
1
Mayuri
4
1050
3
Kavita
5
3000
4
Himanshu
6
425
7
Chetan
7
210
2
Naved
8
777
NULL
Simran
9
115
9
NULL
10
4000
8
Ravi

Example :- 
1. display customer name from sells table whose name's second letter is "a".

i/p:- select cust_name from sells where cust_name like. "_a%";

o/p :- 
cust_name
Tarun
Mayuri
Kavita
Naved
Ravi

2. Display customer's name from sells whose name's last letter is "i".

i/p :- select cust_name from sells where cust_name like "i%";


o/p :- 
Mayuri
Ravi

No comments:

Post a Comment

Nested SQL Query or SQL Sub Query in hindi in english

if a SQL query is used inside another SQL query then this type of SQL query is called sub-query.  यदि किसी SQL क्वेरी का उपयोग, किसी अन्य SQ...