Home » SQL

Wildcards Examples in SQL

In this article, we are going to use wildcards like (_, %) to manipulate resultSet came out from query.
Submitted by Manu Jemini, on March 04, 2018

The Common operation in modern day softwares such websites is searching for the particular record from the database. Now, the database cannot do this without the use of these wildcards, but it will need at least one unique key to do the searching and what if we don’t have that unique id.

To solve this problem, we use wildcards, now what these wildcards do? It takes one or more keys and matches them with records in one or more tables. When something matches the key it will be returned as a result.

Now in the example given below, we can see how we can easily use these wildcards together and get the desired result? Here, we have dummy data with us, in that dummy data we have salary now we want to get the salaries in the range of twenty thousand, mind you here the salary field in varchar so we cannot use arithmetic operators like > or <.

So, what this will do is it will fetch all the records with salary starting from 2 and ending with 0 having three characters in between.

Dummy data:

SQL - wildcard example 1

Use of Wildcard operator % and _ (Underscore)


SELECT * FROM 'includehelp'.'employee' WHERE SALARY LIKE '2___0';
SQL - wildcard example Output 1


SELECT * FROM 'includehelp'.'employee' WHERE SALARY LIKE '_2%0';
SQL - wildcard example Output 2


SELECT * FROM 'includehelp'.'employee' WHERE SALARY LIKE '3_%_%_%_%'
SQL - wildcard example Output 3

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.