what's effective way of doing it

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
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

what's effective way of doing it

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: what's effective way of doing it

Post 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";
(#10850)
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

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