0

SQL question

I have this question. Let assume that in the row with id 2, 5, 7 everything is unique except the city that is equal only for 2 and 5. Why if I run this query SELECT DISTINCT * FROM table WHERE id IN (2, 5, 7); gives me the same result as the one without distinct? Shouldn't I get only row with unique city instead of seeing all of them?

26th Apr 2020, 3:42 PM
Francesco Malorgio
Francesco Malorgio - avatar
2 Antworten
+ 1
By saying 'DISTINCT *' you select all rows which all values are not similar to any other row. To select rows whose city are distinct. Use this SELECT `id`, DISTINCT `city` FROM `table` WHERE `id` IN (2, 5, 7)
26th Apr 2020, 3:53 PM
Ore
Ore - avatar
0
When you use * it takes all the row and you dont have a duplicate row. So the results would be the same
28th Apr 2020, 8:44 AM
Dot
Dot - avatar