🧚 주목! Beekeeper Studio는 빠르고 현대적이며 오픈 소스 데이터베이스 GUI입니다 다운로드
January 13, 2026 작성자: Matthew Rathbone

Searching for text within your database is one of the most common operations you’ll perform. Whether you’re looking for customer names, filtering product descriptions, or finding records that match a pattern, SQL provides powerful tools for text searching. The LIKE operator is your primary tool for pattern matching in SQL.

Throughout this guide, you’ll find interactive SQL exercises that let you practice pattern matching in your browser—no database setup required. Write queries, get instant feedback, and build your skills with real examples.

Understanding SQL Pattern Matching

SQL doesn’t have a dedicated “contains” function like some programming languages. Instead, it uses the LIKE operator combined with wildcard characters to search for patterns within text. This approach is both powerful and flexible, allowing you to match anything from simple substrings to complex patterns.

The basic syntax is:

SELECT column_name
FROM table_name
WHERE column_name LIKE 'pattern';

The Two SQL Wildcards

SQL provides two wildcard characters for pattern matching:

Wildcard Description Example
% Matches any sequence of characters (including zero characters) '%test%' matches “test”, “testing”, “latest”
_ Matches exactly one character 't_st' matches “test”, “tast”, but not “toast”

Understanding these wildcards is the key to mastering SQL text searches.

Searching for Text That Contains a Substring

The most common text search is checking if a column contains a specific word or phrase. Use the % wildcard on both sides of your search term:

SELECT * FROM customers
WHERE company_name LIKE '%Tech%';

This query finds all customers where company_name contains “Tech” anywhere—at the beginning, middle, or end. It would match:

  • “Tech Solutions Inc”
  • “FinTech Corp”
  • “Technology Partners”

Try it yourself:

[[ expanded ? '▼' : '▶' ]]

[[ testData.title ]]

Query the products table to find all products where the name contains the word “Pro”. Return the id and name columns.

인터랙티브 예제 ✓ 완료
예상 열: [[ col ]]
ℹ️ 이 연습은 실행할 때마다 데이터베이스를 초기화합니다. 완전한 솔루션을 한 번에 작성하세요.
[[ i18n.correct ]] [[ validationResult ? i18n.all_checks_passed : i18n.query_success ]]
[[ detail.message ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.not_quite_right ]] [[ patternError ]] [[ validationResult.error ]] [[ i18n.results_dont_match ]]
[[ detail.passed ? '✓' : '✗' ]] [[ detail.message ]]
[[ i18n.your_results ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.expected_results ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.sql_error ]]
[[ error ]]
💡 [[ i18n.hint_label ]] [[ testData.hint ]]
📊 [[ i18n.expected_result_label ]]
[[ col ]]
[[ formatCell(cell) ]]
✨ [[ i18n.solution_label ]]
[[ testData.solution ]]
사용 가능한 테이블
[[ table.name ]]
[[ col ]]
[[ formatCell(cell) ]]

Pattern Positions: Starts With, Ends With, Contains

You can control where the pattern appears by positioning your wildcards:

SELECT * FROM products
WHERE name LIKE 'iPhone%';

Matches: “iPhone 15”, “iPhone Pro Max”
Does not match: “New iPhone Case”

SELECT * FROM files
WHERE filename LIKE '%.pdf';

Matches: “report.pdf”, “invoice.pdf”
Does not match: “pdf_guide.txt”

Contains (Anywhere)

SELECT * FROM messages
WHERE content LIKE '%urgent%';

Matches anywhere the word “urgent” appears.

Try it yourself:

[[ expanded ? '▼' : '▶' ]]

[[ testData.title ]]

Query the employees table to find all employees whose email starts with the letter ‘j’. Return id, name, and email, ordered by name.

인터랙티브 예제 ✓ 완료
예상 열: [[ col ]]
ℹ️ 이 연습은 실행할 때마다 데이터베이스를 초기화합니다. 완전한 솔루션을 한 번에 작성하세요.
[[ i18n.correct ]] [[ validationResult ? i18n.all_checks_passed : i18n.query_success ]]
[[ detail.message ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.not_quite_right ]] [[ patternError ]] [[ validationResult.error ]] [[ i18n.results_dont_match ]]
[[ detail.passed ? '✓' : '✗' ]] [[ detail.message ]]
[[ i18n.your_results ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.expected_results ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.sql_error ]]
[[ error ]]
💡 [[ i18n.hint_label ]] [[ testData.hint ]]
📊 [[ i18n.expected_result_label ]]
[[ col ]]
[[ formatCell(cell) ]]
✨ [[ i18n.solution_label ]]
[[ testData.solution ]]
사용 가능한 테이블
[[ table.name ]]
[[ col ]]
[[ formatCell(cell) ]]

Using Underscore for Precise Matching

The underscore wildcard (_) matches exactly one character, which is useful when you know the pattern’s structure:

SELECT * FROM products
WHERE product_code LIKE 'A__-___';

This matches codes like “A12-345” or “ABC-XYZ” but not “A1-234” or “ABCD-123”.

Common use cases for underscore:

  • Matching fixed-format codes (SKUs, part numbers)
  • Finding values with specific character positions
  • Validating data formats

Try it yourself:

[[ expanded ? '▼' : '▶' ]]

[[ testData.title ]]

Query the inventory table to find all items where the sku has exactly 3 characters followed by ‘-001’. Return sku and item_name, ordered by sku.

인터랙티브 예제 ✓ 완료
예상 열: [[ col ]]
ℹ️ 이 연습은 실행할 때마다 데이터베이스를 초기화합니다. 완전한 솔루션을 한 번에 작성하세요.
[[ i18n.correct ]] [[ validationResult ? i18n.all_checks_passed : i18n.query_success ]]
[[ detail.message ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.not_quite_right ]] [[ patternError ]] [[ validationResult.error ]] [[ i18n.results_dont_match ]]
[[ detail.passed ? '✓' : '✗' ]] [[ detail.message ]]
[[ i18n.your_results ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.expected_results ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.sql_error ]]
[[ error ]]
💡 [[ i18n.hint_label ]] [[ testData.hint ]]
📊 [[ i18n.expected_result_label ]]
[[ col ]]
[[ formatCell(cell) ]]
✨ [[ i18n.solution_label ]]
[[ testData.solution ]]
사용 가능한 테이블
[[ table.name ]]
[[ col ]]
[[ formatCell(cell) ]]

Case Sensitivity in Pattern Matching

LIKE behavior varies by database:

Database Default Behavior
PostgreSQL Case-sensitive
MySQL Case-insensitive (with default collation)
SQLite Case-insensitive for ASCII letters
SQL Server Depends on collation settings

To ensure consistent case-insensitive searches, use the LOWER() or UPPER() function:

SELECT * FROM customers
WHERE LOWER(name) LIKE '%smith%';

This finds “Smith”, “SMITH”, “smith”, and “SmItH”.

PostgreSQL alternative: Use ILIKE for case-insensitive matching:

SELECT * FROM customers
WHERE name ILIKE '%smith%';

Try it yourself:

[[ expanded ? '▼' : '▶' ]]

[[ testData.title ]]

Query the articles table to find all articles where the title contains “sql” (case-insensitive). Return id and title, ordered by id.

인터랙티브 예제 ✓ 완료
예상 열: [[ col ]]
ℹ️ 이 연습은 실행할 때마다 데이터베이스를 초기화합니다. 완전한 솔루션을 한 번에 작성하세요.
[[ i18n.correct ]] [[ validationResult ? i18n.all_checks_passed : i18n.query_success ]]
[[ detail.message ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.not_quite_right ]] [[ patternError ]] [[ validationResult.error ]] [[ i18n.results_dont_match ]]
[[ detail.passed ? '✓' : '✗' ]] [[ detail.message ]]
[[ i18n.your_results ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.expected_results ]]
[[ col ]]
[[ formatCell(cell) ]]
[[ i18n.sql_error ]]
[[ error ]]
💡 [[ i18n.hint_label ]] [[ testData.hint ]]
📊 [[ i18n.expected_result_label ]]
[[ col ]]
[[ formatCell(cell) ]]
✨ [[ i18n.solution_label ]]
[[ testData.solution ]]
사용 가능한 테이블
[[ table.name ]]
[[ col ]]
[[ formatCell(cell) ]]

Escaping Special Characters

What if you need to search for actual % or _ characters? Use the ESCAPE clause:

SELECT * FROM discounts
WHERE description LIKE '%50\%%' ESCAPE '\';

This searches for “50%” literally. The backslash tells SQL to treat the following % as a regular character, not a wildcard.

Common scenarios:

  • Searching for percentage values (“50%”, “25% off”)
  • Finding filenames with underscores (“report_2024”)
  • Matching URLs or file paths

NOT LIKE: Excluding Patterns

Use NOT LIKE to find records that don’t match a pattern:

SELECT * FROM users
WHERE email NOT LIKE '%@gmail.com';

This finds all users who don’t have Gmail addresses. Combine with other conditions for more complex filtering:

SELECT * FROM products
WHERE name NOT LIKE '%discontinued%'
  AND name NOT LIKE '%legacy%';

Combining Multiple Patterns with OR

Search for multiple patterns using OR:

SELECT * FROM products
WHERE name LIKE '%laptop%'
   OR name LIKE '%notebook%'
   OR name LIKE '%computer%';

This finds products matching any of these terms.

Performance Considerations

Pattern matching can be slow on large tables, especially with leading wildcards:

Slow (Cannot Use Index)

SELECT * FROM products
WHERE name LIKE '%widget%';  -- Leading wildcard

The database must scan every row because it can’t predict where “widget” might appear.

Fast (Can Use Index)

SELECT * FROM products
WHERE name LIKE 'widget%';  -- No leading wildcard

When the pattern starts with literal characters, the database can use an index to quickly find matching rows.

Optimization Tips

  1. Avoid leading wildcards when possible
  2. Create indexes on frequently searched columns
  3. Consider full-text search for complex text searching needs
  4. Limit result sets with additional WHERE conditions
SELECT * FROM products
WHERE category = 'Electronics'  -- Filter first
  AND name LIKE '%pro%';        -- Then pattern match

For heavy text searching needs, consider full-text search capabilities:

PostgreSQL:

SELECT * FROM articles
WHERE to_tsvector('english', content) @@ to_tsquery('database & performance');

MySQL:

SELECT * FROM articles
WHERE MATCH(title, content) AGAINST('database performance');

Full-text search offers:

  • Better performance on large text fields
  • Relevance ranking
  • Word stemming (finding “running” when searching “run”)
  • Stop word handling

Common Patterns Quick Reference

Goal Pattern Example
Contains “word” '%word%' LIKE '%error%'
Starts with “word” 'word%' LIKE 'Dr.%'
Ends with “word” '%word' LIKE '%.pdf'
Exactly 3 characters '___' LIKE '___'
Starts with letter, 3 digits '_###' (conceptual) LIKE 'A___'
Second character is ‘a’ '_a%' LIKE '_a%'

Working with Pattern Matching in Beekeeper Studio

When building complex LIKE queries, having a good SQL editor makes development much easier. Beekeeper Studio provides helpful features for working with pattern matching:

  • Autocomplete: Suggests column names to avoid typos in your WHERE clauses
  • Query formatting: Keeps complex multi-pattern queries readable
  • Result highlighting: Easily spot matched patterns in your results
  • Multi-database support: Consistent experience across PostgreSQL, MySQL, SQLite, and more

The free version includes everything you need for mastering SQL pattern matching.

Key Takeaways

SQL pattern matching with LIKE is essential for searching text in your database. Here’s what to remember:

  • Use % to match any characters (zero or more) - this is your “contains” search
  • Use _ to match exactly one character - great for fixed-format patterns
  • Position wildcards strategically: %word (ends with), word% (starts with), %word% (contains)
  • Handle case sensitivity with LOWER() or database-specific functions like ILIKE
  • Escape special characters when searching for literal % or _
  • Avoid leading wildcards when possible for better performance
  • Consider full-text search for complex text searching needs

Pattern matching is a fundamental SQL skill. Whether you’re filtering customer data, searching logs, or building search functionality, the LIKE operator gives you the flexibility to find exactly what you need.

Ready to practice more? Try the interactive examples above, or explore more SQL tutorials to continue building your database skills.

Beekeeper Studio는 무료 & 오픈 소스 데이터베이스 GUI입니다

제가 사용해 본 최고의 SQL 쿼리 & 편집기 도구입니다. 데이터베이스 관리에 필요한 모든 것을 제공합니다. - ⭐⭐⭐⭐⭐ Mit

Beekeeper Studio는 빠르고 직관적이며 사용하기 쉽습니다. Beekeeper는 많은 데이터베이스를 지원하며 Windows, Mac, Linux에서 훌륭하게 작동합니다.

Beekeeper의 Linux 버전은 100% 완전한 기능을 갖추고 있으며, 기능 타협이 없습니다.

사용자들이 Beekeeper Studio에 대해 말하는 것

★★★★★
"Beekeeper Studio는 제 예전 SQL 워크플로를 완전히 대체했습니다. 빠르고 직관적이며 데이터베이스 작업을 다시 즐겁게 만들어 줍니다."
— Alex K., 데이터베이스 개발자
★★★★★
"많은 데이터베이스 GUI를 사용해 봤지만, Beekeeper는 기능과 단순함 사이의 완벽한 균형을 찾았습니다. 그냥 작동합니다."
— Sarah M., 풀스택 엔지니어

SQL 워크플로를 개선할 준비가 되셨나요?

download 무료 다운로드