0
0
PostgreSQLquery~5 mins

Pattern matching with LIKE and ILIKE in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the LIKE operator do in SQL?
The LIKE operator is used to search for a specified pattern in a column. It matches text based on wildcard characters like % for any sequence of characters and _ for a single character.
Click to reveal answer
beginner
What is the difference between LIKE and ILIKE in PostgreSQL?
LIKE is case-sensitive, meaning it distinguishes uppercase and lowercase letters. ILIKE is case-insensitive, so it matches letters regardless of case.
Click to reveal answer
beginner
What does the wildcard % represent in a LIKE pattern?
The % wildcard matches zero or more characters of any kind. For example, 'a%' matches any string starting with 'a'.
Click to reveal answer
beginner
How do you match exactly one character in a pattern using LIKE?
Use the underscore _ wildcard to match exactly one character. For example, 'b_t' matches 'bat', 'bit', or 'but'.
Click to reveal answer
intermediate
Write a query to find all names starting with 'Jo' ignoring case using ILIKE.
Example query: <br>SELECT * FROM users WHERE name ILIKE 'Jo%'; <br>This finds names like 'John', 'joanna', or 'JOSEPH'.
Click to reveal answer
Which wildcard matches any number of characters in a LIKE pattern?
A%
B_
C*
D?
What does ILIKE do differently than LIKE in PostgreSQL?
AMatches patterns case-insensitively
BMatches patterns only at the start of the string
CMatches patterns only at the end of the string
DMatches patterns with regular expressions
Which pattern matches any single character in LIKE?
A%
B?
C_
D#
What will WHERE name LIKE 'A%' return?
ANames containing 'A' anywhere
BNames ending with 'A'
CNames exactly equal to 'A'
DNames starting with 'A'
Which query finds names like 'Sam', 'sam', or 'SAM'?
ASELECT * FROM users WHERE name LIKE 'Sam';
BSELECT * FROM users WHERE name ILIKE 'Sam';
CSELECT * FROM users WHERE name LIKE '%Sam%';
DSELECT * FROM users WHERE name = 'Sam';
Explain how to use LIKE and ILIKE for pattern matching in PostgreSQL.
Think about how you find words that start with or contain certain letters.
You got /4 concepts.
    Describe the difference between the wildcards % and _ in SQL pattern matching.
    One wildcard is for many characters, the other for just one.
    You got /2 concepts.