SQL LIKE(Wildcard)
The LIKE operator in SQL Server is used in the WHERE clause to filter records based on pattern matching. It is commonly used with wildcards to find values that match a specific format.
Syntax:
column_name LIKE 'pattern'
Example:Find all products starting with 'L'
SELECT OrderID, ProductName FROM Orders WHERE ProductName LIKE 'L%';
Example Using _ Wildcard: Find products with 5 letters, starting with 'M'
SELECT ProductName FROM Orders WHERE ProductName LIKE 'M____';
Example Using [] Brackets: Find products starting with 'L' or 'K'
SELECT ProductName FROM Orders WHERE ProductName LIKE '[LK]%';
Using [^] (NOT) Brackets Query: Find products NOT starting with 'L' or 'M'
SELECT ProductName FROM Orders WHERE ProductName LIKE '[^LM]%';
Notes:
1. Case-insensitive: By default, LIKE is case-insensitive in SQL Server unless the collation is case-sensitive.
2. Often used with % to search anywhere in a string:
    • Example: WHERE ProductName LIKE '%top%'
    • Matches 'Laptop', 'Desktop', etc.
3. Can be combined with NOT LIKE to exclude patterns.
Quick Tip:
LIKE in SQL Server is used for pattern matching with wildcards such as % (any sequence) and _ (single character). Useful for searching text columns flexibly.