Hello I have a query like this:
SELECT otel_id
FROM YAZILIM_menu_icerik
WHERE YAZILIM_menu_icerik.menu_id = 39
AND otel_id IN (
SELECT otel_id
FROM YAZILIM_menu_icerik
WHERE menu_id =$id
ORDER BY RAND()
)
LIMIT 0,20
It should display randomly 20 hotels each time it works but instead , i'm ending up getting the same 20 hotel each time. Long story short RAND()
doesn't seem to work and I can't seem to find any logical error.
EDIT: Problem solved. Mysql doesn't see inner RAND() so here's the correct way to do it:
SELECT otel_id
FROM YAZILIM_menu_icerik
WHERE YAZILIM_menu_icerik.menu_id = 39
AND otel_id IN (
SELECT otel_id
FROM YAZILIM_menu_icerik
WHERE menu_id =$id
)
ORDER BY RAND()
LIMIT 0,20
ORDER BY RAND()
is terribly inefficient - you should probably try and find another solution. Regardless, if you move theORDER BY RAND()
to outside the)
, does it work?