Be able to perform searches using wildcards

Resources | Subject Notes | Information Communication Technology ICT

ICT 0417 - Databases - Wildcard Searches

Databases - Wildcard Searches

Introduction

In database systems, searching for specific data can be achieved using various criteria. One powerful tool for flexible searching is the use of wildcards. Wildcards allow you to represent unknown or variable characters in a search query, making it possible to retrieve a wider range of results.

Wildcard Characters

Two common wildcard characters are used in database searches:

  • ? (Question Mark): Represents a single character.
  • * (Asterisk): Represents zero or more characters.

Using the '?' Wildcard

The '?' wildcard is used to find records where a specific character is unknown. For example:

  • Searching for 'J?ne' would find 'Jane', 'Jane', 'June', etc.
  • Searching for 'S?m' would find 'Sam', 'Sim', 'Som', etc.

Using the '*' Wildcard

The '*' wildcard is used to find records where a sequence of characters is unknown or can be of varying lengths. For example:

  • Searching for 'El*' would find 'Eleanor', 'Ella', 'Emily', etc.
  • Searching for 'Joh*' would find 'John', 'Johanna', 'Johnson', etc.
  • Searching for '*an*' would find 'Anna', 'Susan', 'Brian', etc.

Combining Wildcards

Some database systems allow you to combine wildcards to create more complex search queries. The exact syntax for combining wildcards can vary depending on the database system being used.

Example Search Queries

Search Query Description
'S*t' Finds records starting with 'S' followed by any number of characters and ending with 't'. Examples: 'Sat', 'Start', 'Smart'.
'Jo?n' Finds records where the first letter is 'J', the second letter is any character, and the third letter is 'n'. Examples: 'Jon', 'Join', 'Jonah'.
'A*' Finds records starting with 'A' followed by any number of characters. Examples: 'Apple', 'Alice', 'A'.

Important Considerations

When using wildcards, it's important to be mindful of the following:

  • Wildcard searches can be computationally expensive, especially with long wildcard sequences.
  • The database system's specific syntax for wildcard searches should be consulted for accurate results.
  • Overuse of wildcards can lead to a large number of irrelevant results.