Maybe you could do something like the following with user variables (or prepared statements):
set @sex = 1, @country = 120, @education = 0; select if(sex_id = @sex, 1, 0) + if(country_id = @country, 1, 0) + if(education_id = @education, 1, 0) as num_matches, sex_id, country_id, education_id from my_table where sex_id = @sex or country_id = @country or education_id = @education order by num_matches desc; -Travis -----Original Message----- From: Ali A.F.N [mailto:alio...@yahoo.com] Sent: Thursday, October 21, 2010 7:58 AM To: mysql@lists.mysql.com Subject: Percent of match in condition Hi All, I have a table with different fileds and almost the type of all them are smallint. I want to search on some fields with "OR" condition. I want to know is there possibility to know how many fileds matched exactly? then I can say how many percent match are available. select * from my_table where sex_id = 1 or country_id = 120 or education_id I mean if in my table there are some records with sex_id = 1 or country_id = 120 then I got 2 (2 match) then I can say 66% percent match. Thank you, ali -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=travis_...@hotmail.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=arch...@jab.org