aldrin151 Posted July 29, 2008 Share Posted July 29, 2008 Hello...I'm having problems retrieving records in certain order...for example I have SELECT * FROM `users` WHERE (`1_tut`=1 or `2_tut`=1 or `3_tut`= 1) AND (`1_av`=1 or `2_av`=1 or `3_av`=1 or `4_av`=1) ORDER BY (`1_tut` and `2_tut` and `3_tut`) and (`1_av` and `2_av` and `3_av` and `4_av`) DESC or without bracketing the order by clause SELECT * FROM `users` WHERE (`1_tut`=1 or `2_tut`=1 or `3_tut`= 1) AND (`1_av`=1 or `2_av`=1 or `3_av`=1 or `4_av`=1) ORDER BY `1_tut` and `2_tut` and `3_tut` and `1_av` and `2_av` and `3_av` and `4_av` DESC All of the fields either have a 0 or 1 value stored and I'm trying to sort the records starting with the ones which have the most matching 1 value ... however I'm getting the record which has the least 1 value first... Can someone help me or point out what I'm doing wrong ... Thanks Quote Link to comment Share on other sites More sharing options...
vikramjeet.singla Posted July 29, 2008 Share Posted July 29, 2008 You may try this: SELECT * FROM `users` WHERE (`1_tut`=1 or `2_tut`=1 or `3_tut`= 1) AND (`1_av`=1 or `2_av`=1 or `3_av`=1 or `4_av`=1) ORDER BY `1_tut` DESC,`2_tut` DESC, `3_tut` DESC, `1_av` DESC, `2_av` DESC, `3_av` DESC, `4_av` DESC Quote Link to comment Share on other sites More sharing options...
aldrin151 Posted July 29, 2008 Author Share Posted July 29, 2008 wow that worked !!!!! Thank you very much for your support.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.