SQL Like Clause – Syntax and Example
Keeping you updated with latest technology trends, Join DataFlair on Telegram
1. Like Clause in SQL
In this SQL tutorial, we are going to learn about the SQL Like Clause. Moreover, in this SQL Like clause, we will see the syntax and example of Like Clause in SQL.
So, let us start SQL Like Clause.
2. What is SQL Like Clause?
The SQL LIKE clause is used to contrast an incentive with comparative qualities utilizing trump card administrators. There are two wild cards used as a part of conjunction with the LIKE administrator.
- The percent sign (%)
- The underscore (_)
Do you know about RDBMS Concept
The percent sign in SQL Like Clause speaks to zero, one or various characters. The underscore speaks to a solitary number or character. These images can be used as a part of mixes.
3. Syntax of SQL Like Clause
The syntax of Like Clause in SQL –
The important syntax of % and _ is as per the following −
SELECT FROM table_name WHERE segment LIKE 'XXXX%' OR SELECT FROM table_name WHERE segment LIKE '%XXXX%' OR SELECT FROM table_name WHERE segment LIKE 'XXXX_' OR SELECT FROM table_name WHERE segment LIKE '_XXXX' OR SELECT FROM table_name WHERE segment LIKE '_XXXX_'
You can join N number of conditions utilizing AND OR administrators. Here, XXXX could be any numeric or string value.
4. Like Clause in SQL Example
The accompanying table has a couple of illustrations demonstrating the WHERE part having diverse LIKE clause with ‘%’ and ‘_’ administrators −
Let’s discuss SQL Expressions
WHERE SALARY LIKE '200%' Finds any qualities that begin with 200. WHERE SALARY LIKE '%200%' Finds any qualities that have 200 in any position. WHERE SALARY LIKE '_00%'
Finds any qualities that have 00 in the second and third positions.
WHERE SALARY LIKE '2_%_%'
Finds any qualities that begin with 2 and are no less than 3 characters long.
WHERE SALARY LIKE '%2'
Finds any qualities that end with 2.
Have a look at SQL Operators
WHERE SALARY LIKE '_2%3'
Finds any qualities that have a 2 in the second position and end with a 3.
WHERE SALARY LIKE '2___3'
Finds any qualities in a five-digit number that begin with 2 and end with 3.
In this example, all the customers having a salary more than 200 will be displayed.
Have a look at SQL distinct Keyword
SQL> SELECT * FROM CUSTOMERS WHERE SALARY LIKE '200%'
5. Conclusion – SQL Like Clause
In this SQL Like Clause tutorial, we learned about the LIKE clause in SQL which is a very important Clause of SQL. Also, we discussed its syntax and example. Still, if any doubt regarding SQL Like Clause, ask in the comment tab.
See also –