SQL-Server-Like-Operator .

In this session i have discussed the SQL Server Like operator .

The SQL Server Like operator is used to matches the given character in the specific pattern . A pattern can include the regular characters and wild characters .


Like syntax

    SELECT column_name FROM tbl_name
    WHERE column_name like pattern 
    


Like operator some example description

Like Operator Desction
select *from tbl where name like 'm%' find the value that will start with m.
select *from tbl where name like '%m' find the value that will end with m.
select *from tbl where name like '_m%' find the m value that will at second position .
select *from tbl where name like 'm%h' find the value that will start with m and end with h.

Database Demo

The following data shown by Employee table of abc database .

EmpID EmpName EmpCity EmpEmail
1 Mathew Noida mathew@gmail.com
2 Ram Noida amita@gmail.com
3 Mahesh Delhi mahesh@gmail.com
4 Smith London smith@gmail.com
5 Monu Delhi monu@gmail.com

Like Operator Example .

The below sql code display the all records where the EmpName will start with m character from Employee table .

    select *from Employee where name like 'm%'
    

The output is look like below .

EmpID EmpName EmpCity EmpEmail
1 Mathew Noida mathew@gmail.com
3 Mahesh Delhi mahesh@gmail.com

The below sql code display the all records where the EmpName will end with m character from Employee table .

    select *from Employee where name like 'm%'
    

The output is look like below .

EmpID EmpName EmpCity EmpEmail
1 Mathew Noida mathew@gmail.com
3 Mahesh Delhi mahesh@gmail.com

The below sql code display the all records where EmpName have m value at second position from Employee table .

    select *from Employee where name like '_m%'
    

The output is look like below .

EmpID EmpName EmpCity EmpEmail
3 Mahesh Delhi mahesh@gmail.com

The below sql code display the all records where EmpName will start with m and end with h character from Employee table .

    select *from Employee where name like 'm%h'
    

The output is look like below .

EmpID EmpName EmpCity EmpEmail
3 Mahesh Delhi mahesh@gmail.com

.



Welcome to AndroidATPoint.

back image                     next image