SQL LIKE Clause - The Coding Shala
Home >> Learn SQL >> SQL Like Clause
The following query will return all the rows that have Name starts with 'A' -
Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.
SQL LIKE Clause
The SQL 'Like' is used in a WHERE Clause to search for a specific pattern in a column means SQL LIKE clause is used to compare a value to similar values using wildcard operators. There are two wildcards used in conjunction with LIKE operator -
- The percent sign(%) - represents zero, one or multiple characters.
- The underscore(_) - represents a single character.
- These symbols can be used together.
SQL LIKE Clause Syntax
The basic SQL LIKE Clause syntax is as follows -
SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern;
SQL LIKE Clause Examples
The following 'emp' table will be used for the examples -
Id Name Age Address Salary 1 Akshay 22 Pune 40000 2 Mohit 21 Delhi 42000 3 Akash 21 Delhi 45000 4 Nikhil 24 Mumbai 50000 5 Smith 24 Pune 50000 6 Akshay 22 Pune 50000 7 Nikhil 24 Mumbai 43000
The following query will return all the rows that have Name starts with 'A' -
SQL >> select * from emp where Name like 'A%'; Output >> Id Name Age Address Salary 1 Akshay 22 Pune 40000 3 Akash 21 Delhi 45000 6 Akshay 22 Pune 50000
The following SQL query return all the records that have the second character of the Name is 'o' -
SQL >> select * from emp where Name like '_o%';; Output >> Id Name Age Address Salary 2 Mohit 21 Delhi 42000
Other Posts You May Like
Prev<< SQL Having Clause NEXT >>SQL With Clause
Comments
Post a Comment