eolas/zk/Wildcards_in_SQL.md

32 lines
737 B
Markdown
Raw Normal View History

2022-12-06 09:29:41 +00:00
---
2024-06-15 11:00:03 +01:00
tags:
- SQL
- databases
2022-12-06 09:29:41 +00:00
---
# Wildcards in SQL
SQL does not use Regex. Instead it has a simpler glob-like syntax for carrying
out string matching.
2022-12-06 09:29:41 +00:00
In order to signal that you wish to compare by a wildcard and not a value, you
have to use the `LIKE` keyword. The actual wildcard operator is `%` .
2022-12-06 09:29:41 +00:00
In an SQL statement, the `%` wild card will match any number of occurrences of
any character. Any characters can appear before or after MacBook and the
record will still be returned:
2022-12-06 09:29:41 +00:00
```sql
SELECT name, cores, release_date
FROM model
WHERE name LIKE '%MacBook%';
```
This wildcard only filters characters that come after `Raspberry` :
```sql
SELECT name, cores, release_date
FROM model
WHERE name LIKE 'Raspberry%';
```