SQL SQL Tutorial SQL Database



SQL Like

SQL Like is a powerful operator used in SQL queries to search for patterns in data. It is used to match a string value against a pattern using wildcards. The Like operator is commonly used in conjunction with the SELECT statement to filter data based on specific criteria.

The Like operator is used to search for a specific pattern in a string. It is similar to the regular expression syntax used in other programming languages. The Like operator uses two wildcards, the percent sign (%) and the underscore (_), to match any number of characters or a single character, respectively.

The Like operator is case-insensitive, meaning that it will match both uppercase and lowercase characters. It is also important to note that the Like operator only works with string values, and cannot be used with numeric or date values.

Examples of SQL Like

Let's take a look at some examples of how the Like operator can be used in SQL queries:

Example 1:

Find all customers whose name starts with the letter 'J':

SELECT * FROM customers
WHERE name LIKE 'J%';

This query will return all customers whose name starts with the letter 'J', such as 'John', 'Jane', and 'James'.

Example 2:

Find all products whose name contains the word 'shirt':

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

This query will return all products whose name contains the word 'shirt', such as 'T-shirt', 'Button-up shirt', and 'Polo shirt'.

Example 3:

Find all orders with an order number that ends in '5':

SELECT * FROM orders
WHERE order_number LIKE '%5';

This query will return all orders with an order number that ends in the digit '5', such as '12345', '67895', and '54325'.

Conclusion

The Like operator is a powerful tool in SQL that allows you to search for patterns in data using wildcards. It is commonly used in conjunction with the SELECT statement to filter data based on specific criteria. By understanding how to use the Like operator, you can write more efficient and effective SQL queries.

References

Activity