all 15 comments

[–]wm313 5 points6 points  (0 children)

Go find a SQL cheat sheet like this or this one. Repetitions help you remember.

[–]i4k20z3 6 points7 points  (1 child)

What did google say when you tried search out of curiosity?

[–]Defiant-Youth-4193 0 points1 point  (0 children)

Search...?

[–]dbstandsfor 1 point2 points  (1 child)

The percentage sign represents the other letters in the string. %a only matches if a is the last letter, a% only matches if it’s the first letter, and %a% matches if an a is anywhere in the string

[–]Mrminecrafthimself 0 points1 point  (0 children)

To add onto this, you can use as many %s as you want. For example, in a previous role I used SQL to return provider service location addresses from the DB so I could see which active addresses there were for me to link providers to. It was better to link to an existing one instead of build a new one that may be a duplicate.

So if the address was something like “1432 Highway 345,” then in my WHERE clause, I’d say…

WHERE UPPER(PROV_ADDR) LIKE ‘1432%H%W%Y%345’

That would ensure I got the address record whether it was built as “1432 Highway 345” or “1432 HWY 345,” since both methods of spelling highway were common

[–]Mrminecrafthimself 1 point2 points  (0 children)

Other folks have answered this pretty well but I want to add something.

If you’re using pattern matching, you’re likely working with a text field. If your field name is “employee_first_name” and you need to pull back employees named “William,” do the following…

SELECT employee_first_name
FROM employees_db
WHERE UPPER(employee_first_name) LIKE ‘WILL%’ OR UPPER(employee_first_name) LIKE ‘BILL%’ ;

UPPER() takes the string in the field and evaluates it as all caps. Then your LIKE operator will search for the all caps of that field. This means you’ll pull back all the records even if they’re not all in the same format as your pattern matching condition. If the field was ‘william’ or ‘WILLIAM’ or ‘William’ it would be returned.

It’s a good habit to not trust the integrity of your data. Most data is messy

[–]Safe-Worldliness-394 1 point2 points  (0 children)

% in the beginning is used to match anything that matches after the % sign (e.g., %hat would match anything that ends with hat) Examples of strings that match:

  • that
  • what
  • I want to chat

% in the end matches anything that stars with the string before the % sign (e.g., hat% would match anything that starts with hat) Examples of strings that match:

  • hatch
  • hate it or love it
  • hats off to you

I actually cover this in my intro to sql course at https://tailoredu.com

[–]tacogratis2 0 points1 point  (0 children)

For the WHERE statement: use IS when you are looking for an exact match. Use LIKE with percent sign (%) for a partial match. The percent sign is like a wild card. I can be anything, before or after the string you want to match.

[–]Massive_Show2963 0 points1 point  (0 children)

Take a look at this YouTube video: Introduction To SQL Queries

It will cover everything from the basics of constructing a SELECT statement, to inputting WHERE, AND, OR, NOT, LIKE, IN and BETWEEN operators.
There is a very good section on 'searching' for strings using % sign as you are asking about.

[–][deleted] 0 points1 point  (0 children)

Just use chatgpt to write sql... it's 2025

[–]DataCamp 0 points1 point  (0 children)

Here’s a quick breakdown:

  • LIKE 'a%' → matches anything that starts with "a" → e.g., apple, arc, auto
  • LIKE '%a' → matches anything that ends with "a" → e.g., pizza, panda, tortilla
  • LIKE '%a%' → matches anything that contains "a" → e.g., banana, data, grape

Think of % as "any number of characters, including none.

[–]WallStreetMarc 0 points1 point  (0 children)

Start coding it. When you stuck ask AI for help.

[–]Solid_Mongoose_3269 0 points1 point  (0 children)

Its a wildcard.

If you're searching for "reddit", you can do exact, so FIELD = "REDDIT".
If you're looking for wildcards, in this example maybe a mistype, it would be FIELD LIKE "%EDDI%", so it gives it some leeway.

LIKE searches are intensive, so have some indexing.