SQL wildcards are special characters used in search queries to represent unknown or variable parts of data in a database. They allow you to perform pattern matching searches, making it easier to find data that matches a specific pattern rather than a precise value. There are mainly two SQL wildcards:
% (Percentage Sign):
The % wildcard represents any sequence of characters (including zero characters) in a search.
It is often used with the LIKE operator to find data that matches a pattern.
Example: Suppose you have a table with a column named name, and you want to find all rows where the names start with "J" and end with any characters. You can use
% like this:
This query will return all rows where the name starts with “J.”
SELECT *
FROM your_table
WHERE name LIKE 'J%';
_ (Underscore):
The _ wildcard represents a single character in a search.
It is also used with the LIKE operator to find data that matches a pattern with a specific character at a particular position.
Example: If you want to find all rows where the code column has a three-letter code where the second letter is "A," you can use
_ like this:
This query will match values like "BAX," "CAT," but not "BAAX" because it only matches a single character.
SELECT *
FROM your_table
WHERE code LIKE '_A_';
SQL wildcards are valuable for flexible and pattern-based searching in databases. They are often used with the
LIKE operator to filter and retrieve rows that meet specific pattern criteria, making it easier to search for data when you don't have precise values.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
SQL wildcards are special characters used in search queries to represent unknown or variable parts of data in a database. They allow you to perform pattern matching searches, making it easier to find data that matches a specific pattern rather than a precise value. There are mainly two SQL wildcards:
The % wildcard represents any sequence of characters (including zero characters) in a search.
It is often used with the LIKE operator to find data that matches a pattern.
Example: Suppose you have a table with a column named name, and you want to find all rows where the names start with "J" and end with any characters. You can use % like this:
This query will return all rows where the name starts with “J.”
The _ wildcard represents a single character in a search.
It is also used with the LIKE operator to find data that matches a pattern with a specific character at a particular position.
Example: If you want to find all rows where the code column has a three-letter code where the second letter is "A," you can use _ like this:
This query will match values like "BAX," "CAT," but not "BAAX" because it only matches a single character.
SQL wildcards are valuable for flexible and pattern-based searching in databases. They are often used with the LIKE operator to filter and retrieve rows that meet specific pattern criteria, making it easier to search for data when you don't have precise values.