MySQL operators are symbols or keywords used in SQL queries to perform specific operations on data. These operators help you manipulate data, perform calculations, compare values, and control the flow of SQL statements.

  1. Write a query to retrieve all employees whose salary is greater than 50,000.

    sql
    SELECT * FROM employees WHERE salary > 50000;
  2. Write a query to find all products with a price less than or equal to 100.

    sql
    SELECT * FROM products WHERE price <= 100;
  3. Write a query to get all students whose age is not equal to 18.

    sql
    SELECT * FROM students WHERE age != 18;
  4. Write a query to display all customers who have made orders with a total amount between 500 and 1000.

    sql
    SELECT * FROM orders WHERE total_amount BETWEEN 500 AND 1000;
  5. Write a query to retrieve all items where the stock is equal to 0.

    sql
    SELECT * FROM inventory WHERE stock = 0;
  6. Write a query to find employees whose job title is either 'Manager', 'Supervisor', or 'Team Lead'.

    sql
    SELECT * FROM employees WHERE job_title IN ('Manager', 'Supervisor', 'Team Lead');
  7. Write a query to get all products whose name starts with the letter 'S'.

    sql
    SELECT * FROM products WHERE product_name LIKE 'S%';
  8. Write a query to display the details of orders where the order date is after January 1, 2023.

    sql
    SELECT * FROM orders WHERE order_date > '2023-01-01';
  9. Write a query to retrieve all students with grades less than or equal to 60, but not equal to 50.

    sql
    SELECT * FROM students WHERE grade <= 60 AND grade <> 50;
  10. Write a query to find customers who live in cities that are not 'New York' or 'Los Angeles'.

sql
SELECT * FROM customers WHERE city NOT IN ('New York', 'Los Angeles');

2. Logical Operators

  1. Write a query to retrieve employees who are either working in the 'Sales' department or have a salary greater than 70,000.
sql
SELECT * FROM employees WHERE department = 'Sales' OR salary > 70000;
  1. Write a query to display customers who live in 'Chicago' and have made orders worth more than 500.
sql
SELECT * FROM customers WHERE city = 'Chicago' AND total_order_value > 500;
  1. Write a query to find all products where the price is less than 50 and the category is not 'Electronics'.
sql
SELECT * FROM products WHERE price < 50 AND category != 'Electronics';
  1. Write a query to get all employees whose age is either less than 25 or greater than 60.
sql
SELECT * FROM employees WHERE age < 25 OR age > 60;
  1. Write a query to retrieve customers who are not from 'Miami' and have placed more than 3 orders.
sql
SELECT * FROM customers WHERE NOT city = 'Miami' AND order_count > 3;