Page 1 of 1

Little query problem..

Posted: Sat Mar 05, 2005 2:35 pm
by John Cartwright

Code: Select all

$result = $db->sql("SELECT * FROM `freepicks` 
                    WHERE `date` >= '". $fc->FirstSecond() ."' AND `date` < '". $fc->FirstSecondDay(1) ."' 
                    GROUP BY `uid` 
                    ORDER BY `date` ASC");
$fc->FirstSeoncd() returns first second of today,
$fc->FirstSecordDay(1) returns first second of tommorow


Now the problem is I only want the first row of each GROUP BY `uid`.
So I only want to find for each `uid` the guys first `freepicks` of today (only 1 pick per person).

Any thoughts?

Posted: Sun Mar 06, 2005 7:26 am
by JAM
Check examples. Not sure it is of interest, but if your MySQL version can manage it, subqueries are one way to go. Never myself needed to do this in that way...

The only other thing I can think of is tmp tables.

Posted: Sun Mar 06, 2005 9:12 am
by John Cartwright
Ah well, 95% of the time the user will only have 1 pick, so I decided to use PHP to handle which rows to show.. no need for subqueries as its such a small amount of data being retrieved.