limit and sort results

A

Anonymous

Guest
ok.. forgive me if this is an easy question. i have searched and searched but im not really sure what to search for.

ok i have a mysql table called Rita with two rows "aid" and pid"

now in each entry the "pid" will be different but the "aid" may be the same for example:

"pid" "aid"
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3

now in the above example 123 is 1, 456 is 2 and 789 is 3.
but what i need to do is only select the lowest "pid" from each "aid" so what i would end up with is 1,4 and 7.

does that make sense.

im still learning php/mysql and this has been bugging me for days so any help would be greatly appreciated.

thanks
 
3 queries might do the job:

SELECT pid FROM table WHERE uid ='1' ORDER BY pid ASC LIMIT 1
SELECT pid FROM table WHERE uid ='2' ORDER BY pid ASC LIMIT 1
SELECT pid FROM table WHERE uid ='3' ORDER BY pid ASC LIMIT 1
 
thanks dude... i thought of that but im expecting the aid (or uid as you put it) to go up to around 50 or possibly 100.. which would mean the same amount of queries which i think would be way too many for my little server :(

so thanks but any more ideas :sad:

thanks
 
okej..then its select all and sort manualy via php script... however there was some SQL to do that but i simply dont remember it... :(
 
ok thanks... i know there is probably a simple solution but ive been looking everywhere and cant seem to find it..

its like :shock:

keep going round in circles and ending up at the same place :(
 
search on this forum... in my sql and php coding or php general or php coding... we had it here somewhere.. about a month or 2 ago..
 
Thanks dude i found a solution

SELECT pid FROM rita GROUP BY aid ORDER BY aid ASC

:grin:

thanks again
 
no i got the answer from

http://www.webdesignforums.net/showthread.php?p=162151#post162151
 
Back
Top