CodeEraFree roadmap

SQL Practice / SELECT command

SQL SELECT Statement: practice questions with answers

6 questions with solved queries and real output. Outputs checked on MariaDB 10.11 (MySQL-compatible) on 23 November 2026.

SELECT reads data from a table. Use * for every column or list the columns you need. DISTINCT removes duplicate rows from the result, AS gives a column a new name, and you can calculate new columns straight in the query, such as salary * 12.

These questions use a small employee table with 10 rows (set it up below).

SELECT column1, column2 FROM table_name;
SELECT DISTINCT column FROM table_name;
SELECT column, column * 12 AS new_name FROM table_name;
Set up the practice tables

Copy this script and run it once.

CREATE TABLE employee (
  id         INT PRIMARY KEY,
  name       VARCHAR(50) NOT NULL,
  salary     INT,
  department VARCHAR(50),
  dob        DATE
);

INSERT INTO employee VALUES
(101,'Jack',2000,'HR','1997-05-19'),
  (102,'Jack',NULL,'HR',NULL),
  (103,'Mack',6000,'Developer','1997-03-10'),
  (104,'Peter',4000,'Tester','1998-07-16'),
  (105,'Tom',3000,'HR','1998-11-03'),
  (106,'Leo',2500,'Developer','1997-10-10'),
  (107,'Roger',5300,'Accounts','1997-06-17'),
  (108,'Mike',2000,NULL,'1998-03-09'),
  (109,'Paul',4800,'Developer','1998-12-28'),
  (110,'Hannah',2000,'Accounts','1999-09-26');

Table: employee

idnamesalarydepartmentdob
101Jack2000HR1997-05-19
102JackNULLHRNULL
103Mack6000Developer1997-03-10
104Peter4000Tester1998-07-16
105Tom3000HR1998-11-03
106Leo2500Developer1997-10-10
107Roger5300Accounts1997-06-17
108Mike2000NULL1998-03-09
109Paul4800Developer1998-12-28
110Hannah2000Accounts1999-09-26

How to use this page: read a question, write your own query, then open "Show the answer" and compare. Trying first is what makes it stick.

Question 1Display all the records of the employee table.

Show the answer and the output
SELECT * FROM employee;

Output

idnamesalarydepartmentdob
101Jack2000HR1997-05-19
102JackNULLHRNULL
103Mack6000Developer1997-03-10
104Peter4000Tester1998-07-16
105Tom3000HR1998-11-03
106Leo2500Developer1997-10-10
107Roger5300Accounts1997-06-17
108Mike2000NULL1998-03-09
109Paul4800Developer1998-12-28
110Hannah2000Accounts1999-09-26

Question 2Display the unique salaries of the employee table.

Show the answer and the output
SELECT DISTINCT salary FROM employee;

Output

salary
2000
NULL
6000
4000
3000
2500
5300
4800

DISTINCT treats NULL as one value, so it appears once in the result.

Question 3Display the name and dob columns of the employee table.

Show the answer and the output
SELECT name, dob FROM employee;

Output

namedob
Jack1997-05-19
JackNULL
Mack1997-03-10
Peter1998-07-16
Tom1998-11-03
Leo1997-10-10
Roger1997-06-17
Mike1998-03-09
Paul1998-12-28
Hannah1999-09-26

Question 4Display id, name and the annual salary with the column name 'annual_salary'.

Show the answer and the output
SELECT id, name, salary * 12 AS annual_salary FROM employee;

Output

idnameannual_salary
101Jack24000
102JackNULL
103Mack72000
104Peter48000
105Tom36000
106Leo30000
107Roger63600
108Mike24000
109Paul57600
110Hannah24000

Anything multiplied by NULL is NULL, so employees with no salary show NULL.

Question 5Display the unique combinations of salary and department.

Show the answer and the output
SELECT DISTINCT salary, department FROM employee;

Output

salarydepartment
2000HR
NULLHR
6000Developer
4000Tester
3000HR
2500Developer
5300Accounts
2000NULL
4800Developer
2000Accounts

With two columns, DISTINCT removes rows where the pair of values repeats.

Question 6Display the id and the name with the salary in parentheses, with the result column named emp_detail.

Show the answer and the output
SELECT id, CONCAT(name, '(', salary, ')') AS emp_detail FROM employee;

Output

idemp_detail
101Jack(2000)
102NULL
103Mack(6000)
104Peter(4000)
105Tom(3000)
106Leo(2500)
107Roger(5300)
108Mike(2000)
109Paul(4800)
110Hannah(2000)

CONCAT returns NULL if any value inside it is NULL. Jack (102) has no salary, so his emp_detail is NULL. Use CONCAT_WS or IFNULL if you want to avoid that.

Want these as PDFs? Download the question PDF or the answer PDF to practise offline.