Menu

SQL Wildcards – A Detailed Exploration

Detailed explanation on different types of wildcards available across SQL Server, MySQL, Oracle, and MS Access.

Written by Jagdeesh | 3 min read

let’s aim to provide a comprehensive look at SQL wildcards across various types of databases.

Before diving in, it’s essential to have a handy reference point. Here’s a table that outlines the different types of wildcards available across SQL Server, MySQL, Oracle, and MS Access.

WildcardDescriptionSQL ServerMySQLOracleMS Access
%Represents zero, one, or multiple charactersYesYesYesYes
_Represents a single characterYesYesYesYes
[ ]Defines a character set, with any single character matchYesNoNoYes
[^] or [!]Defines a character set, but matches only outside of itYesNoNoYes
Defines a range of charactersYesNoNoYes
*Represents zero, one, or multiple charactersNoNoNoYes
?Represents a single characterNoNoNoYes
#Represents a single number (0-9)NoNoNoYes

Each wildcard character or set of characters has a unique role to play in SQL. They can significantly simplify complex searches and make your database operations more efficient.

Let’s assume you have the following ‘Customers’ table to illustrate the use of these wildcards

output
| ID | Name      | Phone      |
|----|-----------|------------|
| 1  | Alice     | 1234567890 |
| 2  | Bob       | 2345678901 |
| 3  | Charles   | 3456789012 |
| 4  | Deborah   | 4567890123 |
| 5  | Erik      | 5678901234 |
| 6  | Fiona     | 6789012345 |

Now, let’s see how to use these wildcards in your SQL queries.

1) The % and _ Wildcards (SQL Server, MySQL, Oracle, MS Access)

These are the most common wildcards, used to match a string of any characters ( % ) or a single character ( _ ).

For example, if you want to find all customers whose names start with ‘A’, your SQL query might look something like this

sql
SELECT * FROM Customers
WHERE Name LIKE 'A%';

Result:

output
| ID | Name      | Phone      |
|----|-----------|------------|
| 1  | Alice     | 1234567890 |

2) The [ ], [^], and – Wildcards (SQL Server and MS Access)

These wildcards are used to define a character set or a range of characters.

For example, if you want to find any customers whose name starts with a letter from ‘A’ to ‘C’, you could use the following query

sql
SELECT * FROM Customers
WHERE Name LIKE '[A-C]%';

Result:

output
| ID | Name      | Phone      |
|----|-----------|------------|
| 1  | Alice     | 1234567890 |
| 2  | Bob       | 2345678901 |
| 3  | Charles   | 3456789012 |

3) The *, ?, and # Wildcards (MS Access)

In MS Access, * and ? are similar to % and _ in SQL, and # is used to represent a single numeric character.

For instance, to find all customers whose phone number starts with ‘123’ followed by any digit, you would use:

sql
SELECT * FROM Customers
WHERE Phone LIKE '123#*';

Result:

output
| ID | Name      | Phone      |
|----|-----------|------------|
| 1  | Alice     | 1234567890 |

4) The [!] Wildcard (MS Access)

This wildcard matches any character not in the character set.

For example, to find all customers whose names do not start with ‘A’, ‘B’, or ‘C’, you would use

sql
SELECT * FROM Customers
WHERE Name LIKE '[!A-C]*';

Result:

output
| ID | Name      | Phone      |
|----|-----------|------------|
| 4  | Deborah   | 4567890123 |
| 5  | Erik      | 5678901234 |
| 6  | Fiona     | 6789012345 |

Conclusion:

As you can see, SQL wildcards are powerful tools when it comes to data manipulation and retrieval. However, always use them judiciously to avoid unnecessary full-table scans, which can slow down your search process significa

Free Course
Master Core Python — Your First Step into AI/ML

Build a strong Python foundation with hands-on exercises designed for aspiring Data Scientists and AI/ML Engineers.

Start Free Course
Trusted by 50,000+ learners
Jagdeesh
Written by
Related Course
Master SQL — Hands-On
Join 5,000+ students at edu.machinelearningplus.com
Explore Course
Machine Learning Plus
MachineLearningPlus Expert AI/ML Training

Get a Free 30-Min
Guidance Call

Let our ML expert call you back and guide you for free

You're all set!
Tired of tutorials that go nowhere? This video shows you why and what to do instead.
Watch the Free Training
Redirecting in 5 seconds...
No thanks, I'll figure it out myself

Get your Start in AI/ML with the Foundations for Data Science (AI/ML) Course

Enroll for Free
Scroll to Top
Scroll to Top
Course Preview

Machine Learning A-Z™: Hands-On Python & R In Data Science

Free Sample Videos:

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science