Welcome Guest, Not a member yet? Register   Sign In
MySQL: select random rows, but without duplicates
#1

[eluser]codex[/eluser]
Is it possible to select random rows, but without duplicates? Something like this :

(Obviously pseudocode)
Code:
SELECT object_id
FROM objects
ORDER BY RAND()
BUT UNIQUE(object_id)
LIMIT 0, 12
#2

[eluser]Doosje[/eluser]
i think you can do it with distinct !
Code:
SELECT distinct object_id
FROM objects
ORDER BY RAND()
LIMIT 0, 12
#3

[eluser]codex[/eluser]
[quote author="Doosje" date="1218654243"]i think you can do it with distinct !
Code:
SELECT distinct object_id
FROM objects
ORDER BY RAND()
LIMIT 0, 12
[/quote]

I know, and I was under the impression that I tried that and it failed. But I guess I was somewhere else with my thoughts, because DISTINCT does the trick. So thanks :-)




Theme © iAndrew 2016 - Forum software by © MyBB