Page 1 of 1

what's effective way of doing it

Posted: Thu Sep 14, 2006 11:36 pm
by rami
is there better way of doing it
$query = "SELECT matrimonial.matri_id,matrimonial.nationality,matrimonial.caste,matrimonial.aboutme FROM matrimonial,category where(matrimonial.caste=category.cat_id and category.main_cat=6) order by matrimonial.views desc limit 1";

may be from maximum..may be that way only one row will be quried
rather than sorting all
i tried but am confused in its syntax,
if i use max does it return only maximum number of views (ie number)
but i want all the fields vale of max views row

Re: what's effective way of doing it

Posted: Fri Sep 15, 2006 12:34 am
by Christopher
Use ON to associate join keys and WHERE to limit the result set. So something like:

Code: Select all

$query = "SELECT matrimonial.matri_id,matrimonial.nationality,matrimonial.caste,matrimonial.aboutme FROM matrimonial JOIN category ON matrimonial.caste=category.cat_id WHERE category.main_cat=6 ORDER BY matrimonial.views DESC LIMIT 1";

Posted: Fri Sep 15, 2006 5:31 am
by rami
i was not much concerned about joins rather is there way of doing it using max
i will redefined that type of join
but i was trying to do it with max rather than limit 1...
thanks for answer