I’m executing a query which I want to randomize query results from a drupal database.
here’s what I have done…
$res=db_query("SELECT DISTINCT nid FROM content_type_event ORDER BY RANDOM()");
but this query doesn’t work. what’s wrong with this query? please help me to solve this?
Thanks a lot…
You did not tell us which database engine you are using, but maybe
ORDER BY RAND()would be better.Update: okay, PostgreSQL uses
RANDOM()and notRAND()so that’s okay. I’ve found this question which seems to suggest thatORDER BY RANDOM()should work and the error is likely to be elsewhere. Maybe it’sDISTINCTthat is screwing things up; try your query again withoutDISTINCT.