Sobes.tech
Junior

What are the uses of the IN, BETWEEN, and LIKE operators in SQL?

sobes.tech AI

Answer from AI

The IN, BETWEEN, and LIKE operators in SQL are used for filtering data in queries:

  • IN — checks if a value is contained in a specified list. For example:

    SELECT * FROM users WHERE country IN ('USA', 'Canada', 'UK');
    

    Selects users from the specified countries.

  • BETWEEN — checks if a value is within a specified range (inclusive). For example:

    SELECT * FROM orders WHERE order_date BETWEEN '2023-01-01' AND '2023-01-31';
    

    Selects orders from January 2023.

  • LIKE — used for pattern matching with wildcards:

    • % — any number of any characters
    • _ — exactly one of any character

    For example:

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

    Finds products with names starting with "Smart".