Jump to content

[SOLVED] mysql search query


aldrin151

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.