Skip to content
Laviyx Learn

Try

SQL SELECT Practice

Practise reading data with SELECT, choosing columns, calculating values, and filtering rows with WHERE.

Beginner4 problemsUpdated

Review first: SELECT, WHERE

All problems use this employees table:

idnamedepartmentsalarycity
1AshaSales52000Mumbai
2RaviEngineering78000Bengaluru
3MeeraEngineering81000Pune
4JohnMarketing46000Mumbai
5PriyaSales61000Delhi
Try your answers on these tables in the SQL Playground
  1. 1.Names and cities

    Beginner

    Return the name and city of every employee.

    Show hint

    List the two columns after SELECT, separated by a comma.

    Show solution
    SQLRun
    SELECT name, city
    FROM employees;
    Output
    name  | city
    ------+----------
    Asha  | Mumbai
    Ravi  | Bengaluru
    Meera | Pune
    John  | Mumbai
    Priya | Delhi
  2. 2.Monthly salary

    Beginner

    The salary column is a yearly figure. Return each employee's name and their monthly salary as a column called monthly_salary.

    Show hint

    Divide by 12 and name the result with AS.

    Show solution
    SQLRun
    SELECT name, salary / 12 AS monthly_salary
    FROM employees;

    If both values are integers, some databases (PostgreSQL, SQL Server, SQLite) perform integer division and drop the decimals. Write salary / 12.0 to keep them.

  3. 3.Two cities

    Beginner

    Return the name and salary of employees who live in Mumbai or Delhi.

    Show hint

    Use IN ('Mumbai', 'Delhi'), or two conditions joined with OR.

    Show solution
    SQLRun
    SELECT name, salary
    FROM employees
    WHERE city IN ('Mumbai', 'Delhi');
    Output
    name  | salary
    ------+-------
    Asha  | 52000
    John  | 46000
    Priya | 61000
  4. 4.Range and pattern

    Beginner

    Return the names of employees whose salary is between 50,000 and 80,000 (inclusive) and whose name ends with "a".

    Show hint

    Combine BETWEEN and LIKE '%a' with AND.

    Show solution
    SQLRun
    SELECT name
    FROM employees
    WHERE salary BETWEEN 50000 AND 80000
      AND name LIKE '%a';
    Output
    name
    -----
    Asha
    Priya

    Meera also ends with "a", but her salary of 81,000 is outside the range. Ravi is in the range but his name ends with "i".