SELECT, WHERE & ORDER BY · Question 1 · Easy

SELECT, WHERE & ORDER BY question 1

Table Students:
roll | name | city | marks
1 | Aarav | Pune | 78
2 | Diya | Mumbai | 91
3 | Kabir | Pune | 64
4 | Meena | Chennai | 91
5 | Rohan | Mumbai | NULL
6 | Sneha | Pune | 85

What does this query return (one city per row)?

SELECT DISTINCT city
FROM Students
ORDER BY city;
  1. Chennai; Mumbai; Pune
  2. Pune; Mumbai; Chennai
  3. Chennai; Mumbai; Mumbai; Pune; Pune; Pune
  4. Pune; Mumbai; Pune; Chennai; Mumbai; Pune
Answer and explanation

Answer: A. Chennai; Mumbai; Pune

Explanation: DISTINCT keeps each city once, leaving Pune, Mumbai and Chennai. ORDER BY city then sorts them alphabetically: Chennai, Mumbai, Pune.

Next: In the query below, what is stock_value?

Practise select, where & order by

Try a fresh set of select, where & order by questions with an explanation after every answer, free and without signing up: SELECT, WHERE & ORDER BY practice. Or sit a full placement mock test.

More select, where & order by questions

More sql practice

SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge