Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Apr 2005
    Posts
    2
    Member #
    9562
    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 cats 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.

    somebody suggested on another forum to use the following:

    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

    but the problem is with this is im expecting the "aid" field to reach large numbers so if i was to use the above it would result in too many queries


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

    pleeeeeese its bugging me for days and my etes are going funny :tired:

    thanks

  2.  

  3. #2
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    How about...
    Code:
    SELECT pid FROM table GROUP BY uid ORDER BY uid ASC
    ?
    JR

  4. #3
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Code:
    SELECT pid FROM cats GROUP BY aid
    Works as well. It will order aid ASC by default.

    If your records are mixed in such a way that AID 34 comes before AID 33 (meaning that record AID 34 was entered before AID 33, and hence has a lower PID number), then the query will list all AID in ASC order anyway (meaning your list of PID's would not be ASC).
    You can fix this by adding ORDER BY pid behind the above.
    S. Rosland

  5. #4
    Junior Member
    Join Date
    Apr 2005
    Posts
    2
    Member #
    9562
    thanks dude...... works perfectly


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:34 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com