Which SQL keyword ensures unique rows are returned?

Enhance your skills with the CompTIA Data+ Certification Test. Engage with flashcards, tackle challenging multiple choice questions, complete with hints and explanations. Get yourself exam-ready now!

Multiple Choice

Which SQL keyword ensures unique rows are returned?

Explanation:
The key idea is removing duplicates from the result set. The keyword DISTINCT tells the database to return only unique rows. It looks at the values you select and discards any duplicates so each row in the output is different. If you list one column, duplicates in that column are removed; if you list multiple columns, duplicates are defined by the combination of those columns, so only unique combinations appear. For example, SELECT DISTINCT country FROM customers returns each country only once, whereas SELECT country FROM customers could return many repeated country values. If you want every row that’s unique across all columns, you can use SELECT DISTINCT * FROM table. Other options don’t focus on deduplication. GROUP BY is about collapsing rows into groups to perform aggregations, which can yield one row per group but isn’t the same as simply ensuring uniqueness. ORDER BY only sorts results, not remove duplicates, and LIMIT only restricts how many rows are returned.

The key idea is removing duplicates from the result set. The keyword DISTINCT tells the database to return only unique rows. It looks at the values you select and discards any duplicates so each row in the output is different. If you list one column, duplicates in that column are removed; if you list multiple columns, duplicates are defined by the combination of those columns, so only unique combinations appear.

For example, SELECT DISTINCT country FROM customers returns each country only once, whereas SELECT country FROM customers could return many repeated country values. If you want every row that’s unique across all columns, you can use SELECT DISTINCT * FROM table.

Other options don’t focus on deduplication. GROUP BY is about collapsing rows into groups to perform aggregations, which can yield one row per group but isn’t the same as simply ensuring uniqueness. ORDER BY only sorts results, not remove duplicates, and LIMIT only restricts how many rows are returned.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy