Databases for Windows  /   Database Blog  /   Organizer Advantage, Handy Library, SQL Tutor  /   SQL Select   /  SQL Tutor, Select Where Clouse, Wildcards
28/05/2024

SQL SELECT, WHERE clause, Wildcards


Wildcards

Wildcards are special characters used with the LIKE (SIMILAR TO) operators to substitute one or more characters of a string. It is used when defining similar searches, pattern searches, range searches, or set searches.

Wildcard characters

% (Represents zero or more characters)
_ (Represents a single character)
[charlist] (Represents any single character within the brackets)
[^charlist] (Represents any character not in the brackets)
- (Represents any single character within the specified range)

SELECT Wildcards, examples

SELECT title WHERE title LIKE '%computer%';

Finds all book titles with the word computer anywhere in the book title.

SELECT firstname WHERE firstname LIKE '_ean';

Finds all four-letter first names that end with ean (Dean, Sean, and so on).

SELECT lastname WHERE lastname LIKE '[C-P]orson';

Finds last names ending with son and starting with any single character between C and P, for example Corson, Lorson, Korson, and so on. In range searches, the characters included in the range may vary depending on the sorting rules of the collation.

Copyright © 2024 · All Rights Reserved · PrimaSoft PC