Little query problem..

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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Little query problem..

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

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