In the table below, how would you retrieve the unique values for the employee_location without using the DISTINCT keyword? |
||||||||||||||||||||||
We can actually accomplish this with the GROUP BY keyword. Here’s what the SQL would look like:
Running this query will return the following results:
So, you can see that the duplicate values for "Russia" and "Canada" are not returned in the results. This is a valid alternative to using the DISTINCT keyword. If you need a refresher on the GROUP BY clause, then check out this question: Group By and Having. This question would probably be asked just to see how good you are with coming up with alternative options for SQL queries. Although, it probably doesn’t prove much about your SQL skills. |
Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>
Subscribe to our newsletter for more free interview questions.
Follow @programmerintvw