|
Posted by Ridge Burner on 01/20/06 18:39
This is more of a MySQL question I believe, but I do not have any MySQL
newsgroups available to me here except a German one, so hopefully someone
can help me out here.
I have a table that holds events for people, and need to access specific
data for each person with a limit.
For example, I have 10 users who each have 6 events scheduled. I wish to
query for the next 3 events for each user. I can do it like so:
$sql = "SELECT * FROM myTable WHERE user='joe' ORDER BY timestamp ASC LIMIT
3";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)){
$myArray['joe'] = $row;
}
I can do this in turn for each user, no problem. However, I want to know if
I can put this into one SQL command like:
$sql = "SELECT first three records for each distinct user, ORDER BY
timestamp ASC";
(Yes, I know the syntax is wrong, it's just an example)
Hopefully this is possible and someone can help me out on this!
Thanks in advance!
--Ridge
Navigation:
[Reply to this message]
|