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)

Example1:

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

Example2:

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

Example3:

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



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.