Reputation: 63
I have a table called MOVIES:
id|movie
1 |Batman
1 |Batman
2 |Superman
3 |Spiderman
4 |Ironman
4 |Ironman
I want an output like this:
1 |Batman
2 |Superman
3 |Spiderman
4 |Ironman
How can i accomplish this ?
(This is my current code, which doesnt work)
SELECT DISTINCT ID, movie
FROM MOVIES
GROUP By ID, movie
Upvotes: 2
Views: 2945
Reputation:
You should use either DISTINCT or GROUP BY:
DISTINCT - will eliminate duplicates from defined set:
SELECT DISTINCT ID, movie
FROM MOVIES
GROUP BY - is grouping by selected columns, additionally it allows for using aggregate functions, but in simplest form you can use it in the same way as DISTINCT:
SELECT ID, movie
FROM MOVIES
GROUP By ID, movie
As @Lamak noticed there is nothing wrong in using both in this case, it is just unnecessary.
Upvotes: 5