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?
2 Respuestas
+ 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)
0
When you use * it takes all the row and you dont have a duplicate row. So the results would be the same