Orber by
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Have you tried
Key is to put the rand() which I assume is the same as the Postgres RANDOM function into the output list as though it was a column.
Code: Select all
SELECT rand() as ordpos,col1,col2,col3 FROM table ORDER BY ordpos,col2 DESC;Code: Select all
SELECT rand() as ordpos,StarGrade,id,Hotelname FROM Hotels ORDER BY ordpos,StarGradeThanks for your help.Paul
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Logic problem here I think,
rand() returns a random number so each row is a random number, this is unique, so the second order will order consist of one item.
This will order first on StarGrade which I assume is 1-5 stars, followed by the random number.
rand() returns a random number so each row is a random number, this is unique, so the second order will order consist of one item.
Code: Select all
SELECT rand() as ordpos,StarGrade,id,Hotelname FROM Hotels ORDER BY StarGrade,ordposHello, yes
Only thing is i have to put a where clause in it. But when i try it it stops the random. eg
Thanks for the help.
Code: Select all
SELECT rand() as ordpos,StarGrade,id,Hotelname FROM Hotels ORDER BY StarGrade,ordpos limit 200Only thing is i have to put a where clause in it. But when i try it it stops the random. eg
Code: Select all
SELECT rand() as ordpos,StarGrade,id,Hotelname FROM Hotels Where City ='London' ORDER BY StarGrade,ordpos limit 200- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Nothing wrong with the select as I see it... Stupid question...
Do you get results with
is city mixed content or all upper/lowercase?
Do you get results with
Code: Select all
SELECT StarGrade,id,Hotelname FROM Hotels Where City='London' ORDER BY StarGrade LIMIT 200Yea this works But theres no Random in it.
Code: Select all
SELECT StarGrade,id,Hotelname FROM Hotels Where City='London' ORDER BY StarGrade LIMIT 200- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany