Page 1 of 1

need help morphing this to a useable query

Posted: Sat Aug 23, 2003 6:07 pm
by m3rajk
this link below is sli.
http://24.91.157.113/findyourdesire/SQLqueryissue

it shows the response i got..

what i'm trying to do for the forums i'm making is have one query that returns threads by the date they were made ... first giving me the ones that are stickied, both in descending order.

i'm not sure that's possible but figured that with getting this on the test db i made that someone might be able to tell me how to adjust it to work. on that i'm using the tid instead of the date. obviously it's not a real table, the real ones are MUCH more complicated

Posted: Sat Aug 23, 2003 6:39 pm
by nielsene
You can't use AND in the order by clause. Either move it to the where clause or seperate the multiple sorts by a comma.

Code: Select all

mysql> select * from thrdtst where fid='4' order by tid, sticky desc;

Posted: Sat Aug 23, 2003 9:30 pm
by m3rajk
thnx. hmmm. i wanted stickes at the begining of the page display, but considering what i'd be stickying is likely to be rule/regulations type stuff for the forums.... maybe i'll have them on each page....

Posted: Sat Aug 23, 2003 10:58 pm
by nielsene
m3rajk wrote:thnx. hmmm. i wanted stickes at the begining of the page display, but considering what i'd be stickying is likely to be rule/regulations type stuff for the forums.... maybe i'll have them on each page....
OK then, flip the order of your sorts, I think the following order by will work

Code: Select all

order by stickies desc, tid
the database will first sort the result set into descending order baced on the stickes and then within the sticky and no-sticky set will sort into increasing tid.

Posted: Sun Aug 24, 2003 5:08 pm
by m3rajk
that worked perfectly.. although talking to some friends and asking questions of preference to them about important threads.. if they'd prefer it on each page of the forum or only on the first, they seemed to prefer all, only one said just the first. so they way i set it up is how i'll keep it unless i decide to make an anouncement bit and then have three levels like phpbb does.

it''s a good thing toknow though. thank you for the help