need help morphing this to a useable query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

need help morphing this to a useable query

Post 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
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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;
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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....
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
Post Reply