How to Use “Like” in SQL

We have already been learning about the basics of SQL. We’ve learned about SQL itself and how to write select statements.

We have also seen how we can create and delete tables and columns. Now, we’re going to learn a little bit about how to use the Like operator with wildcards to find very specific records in our database tables. For example, we can query our database for all people with first names that begin with the letter “C”.

SELECT * FROM respondents SELECT WHERE
"first_name" LIKE "c%";


search results

Let’s break down the above statement. You will recognize the select statement that starts this line. This will let SQL know we want to select (return) some records. But we can get more specific.

Next, we have the from clause that tells SQL which table in the database we’re interested in. In this case, we’re working with our “respondents” table again. This table contains the names and information about the people who have signed up to receive a newsletter.

The important where clause lets SQL know which column of the table we’re interested in. In this case, we’re working with the “first_name” column of the table. And the like operator lets us get specific.

We are using a wildcard to search only for records where the “first_name” begins with the letter C. That wildcard looks like this: "c%". The quotes open and close the wildcard. The percent sign after the “c” means we don’t care what cames after the first letter, as long as the first letter is a C.

So we are basically telling SQL that we would like to get some records “like” what matches our wildcard.

We have shown you some basic syntax for the like operator and how you can use it in SQL. Stay tuned in our series as we’re going to cover more SQL-related tips and tricks. Let us know in the comments below if you have any questions.

CM
Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

Was this article helpful? Join the conversation!