SQL: Getting Crazy With Wildcards


If you’ve ever met anyone who had the inclination to do anything at anytime, you may already familiar with wildcards. They may not be the most reliable people in the world but they can be fun at the right times. Obviously we are not here to talk about impulsive people but rather the SQL Wildcard.

In SQL a wildcard is used when you need to substitute characters in a string. It is used in conjunction with the LIKE operator, which itself is used with the WHERE statement to search a column for a specified pattern.

Here we have a table listing all Marines and their attributes. Lets take a look at a LIKE example:

WHERE MarineName LIKE 'h%';

This statement will return every Marine whose name begins with the letter “h” as we see in the result-set:

The ‘%’ sign is just one of several wildcard operators that can help us search for different string patterns in our data.

A description of the operator above and some others will help bring things into perspective.

NOTE: Syntax will vary for wildcard operators. The operators listed below are the syntax for MySQL.

%- Represents 0 or more characters_- Represents a single character[]- Represents any single character contained within the brackets^- Represents any character NOT in the brackets- Represents a range of characters

I love traveling, music, and movies.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store