Wildcards in SQL

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

What are Wildcards in SQL?

A wildcard is a character or a group of characters that can be used to replace any other character or characters in a value defined by its constraints. In SQL, the LIKE operator uses wildcard characters. The LIKE operator is used to look for a certain pattern in a column when used with the WHERE clause.

Why Do We Need Wildcards in SQL?

Imagine that you are tasked with finding the salaries of all people whose names start with A. Alternatively, imagine you want to find the salaries of people whose name starts and ends with A. All the data is stored in SQL in the form of tables in a database. Such a task would be difficult using simple SELECT queries. That's where wildcards enter. SQL Wildcards are used to search for complex data and are handy in speeding up the querying process.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

How Many Wildcards are There in SQL?

In SQL, wildcards are used with the LIKE operator. There are 4 wildcards in SQL. They are as follows:

WildcardDescription
%Zero or more characters
_Single Character
[list_of_char]Range of characters to match
[!list_of_char]Sets the range of characters to not be matched
[^list_of_char]Sets the range of characters to not be matched

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Examples of Wildcards in SQL

To understand the concept of wildcards in detail, we will consider a table DETAILS that will be used for the examples below.

NameLocationColour
AnnaPeruRed
AdyaChileRed
AparjeetDubaiYellow
BohemaSingaporeGreen
CathyKenyaWhite

1. %Description: The percentage sign (%) is used to match zero or more characters. The characters can be either digits, alphabets or special characters.

Syntax:

Example 1: Display details of those whose names start in A.

Output:

NameLocationColour
AnnaPeruRed
AdyaChileRed
AparjeetDubaiYellow

Example 2: Display details of those whose name end with an A.

Output:

NameLocationColour
AnnaPeruRed
AdyaChileRed
BohemaSingaporeGreen

Example 3: Display details of those whose name contain an A.

Output:

NameLocationColour
AnnaPeruRed
AdyaChileRed
AparjeetDubaiYellow
BohemaSingaporeGreen
CathyKenyaWhite

2. _ Description: The underscore (_) is used to denote a single character. The characters can be either digits, alphabets or special characters.

Syntax:

Example 1: Colour containing 3 characters and ending with 'ed'

Output:

NameLocationColour
AnnaPeruRed
AdyaChileRed

Example 2: Colour containing 5 characters and starting with 'Wh'

Output:

NameLocationColour
CathyKenyaWhite

3. [list_of_char] Description: Matches a character with a character in the list of characters that are surrounded by square brackets.

Syntax:

Example 1: Details of one whose location contains at least one vowel.

Output:

NameLocationColour
AnnaPeruRed
AdyaChileRed
AparjeetDubaiYellow
BohemaSingaporeGreen
CathyKenyaWhite

Example 2: Details of one whose location contains ends in any letter between a to e.

Output:

NameLocationColour
AdyaChileRed
BohemaSingaporeGreen
CathyKenyaWhite

4. [!list_of_char] or [^list_of_char] Description: Matches when the character is not equal to any of the characters mentioned in the list. The characters can be either digits, alphabets or special characters.

Syntax:

Example 1: Details of one whose location does not end in the letter E.

Output:

NameLocationColour
AparjeetDubaiYellow
CathyKenyaWhite

Example 2: Details of one whose location does not start with the letter S.

Output:

NameLocationColour
AnnaPeruRed
AdyaChileRed
AparjeetDubaiYellow
CathyKenyaWhite

Learn more about advanced concepts of SQL

To learn more about some interesting and advanced concepts in SQL, check out our SQL Reading List on Scaler Topics.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • Wildcards in SQL are used to match a character or a group of characters in SQL and are often used in the WHERE clause in case of complex queries.
  • They reduce computation times and help in query processing
  • Wildcards are used with the LIKE operator in SQL.
  • There are 4 commonly used wildcards which have been explained with examples in the article above.