Like Clause SQL Server
Hi friends, in this post we will learn about Like Clause SQL Server. Like clause is used with where clause to search specified pattern on a column. There are two wildcard used in like clause.
- Percent sign:- %
- Underscore:- _
Earlier we had discussed about SQL AND & OR Operators, SQL Where Clause, Delete Query SQL Server, SQL Update Statement, SQL Select Statement, SQL Insert Statement, Drop Table SQL Server, Rename Table in SQL Server, Create Table SQL Server, Schema In SQL Server, SQL Server Operators, Data Type in SQL Server and Drop-Delete SQL Server Database Using Management Studio or Query.
Table Structure:
ID | NAME | CLASS | PERMADDRESS | TEMPADDRESS |
1 | MANN | XI | AGRA | NULL |
2 | JAI | X | MUMBAI | NULL |
3 | AKSHAY | IX | GOA | NULL |
4 | OM | V | DELHI | NULL |
5 | AMAN | VII | GOA | NULL |
6 | AMIT | VII | JAIPUR | NULL |
Like Clause SQL Server examples:-
----SELECT DATABASE---- USE HIGHTECHNOLOGY GO ----LIKE CLAUSE EXAMPLES---- ----FINDS ANY VALUE THAT START WITH MA---- SELECT * FROM STUDENT_INFORMATION WHERE NAME LIKE 'MA%' GO ---FINDS ANY VALUE THAT HAVE MA AT ANY WHERE IN NAME---- SELECT * FROM STUDENT_INFORMATION WHERE NAME LIKE '%MA%' GO ----FINDS ANY VALUE THAT HAVE ATLEAST 4 CHARACTER AND START WITH MA---- SELECT * FROM STUDENT_INFORMATION WHERE NAME LIKE 'MA__%' GO ----FINDS ANY VALUE THAT HAVE 3 CHARACTER AND START WITH J AND END WITH I---- SELECT * FROM STUDENT_INFORMATION WHERE NAME LIKE 'J_I' GO