Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    Not agregated column/ order before group by

    Code:
    a   b   c          d
    
    1   2   beta      2
    1   1   alpha     1
    1   3   gama      3
    Code:
    select a,min(b), c
    group by a
    result --> 1 1 randome_c

    How would I get , insted of randome_c, exactly 'alpha' based on fact that
    column d has minimum at that record ? 'alpha' is just sample, it is realy randome string.
    Last edited by BubikolRamios; 06-13-2011 at 04:46 AM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,901
    Thanks
    79
    Thanked 4,422 Times in 4,387 Posts
    Code:
    SELECT t.a, t.b, t.c, t.d
    FROM table AS t, ( SELECT a, min(b) AS minb FROM table GROUP BY a ) AS x
    WHERE t.a = x.a
    AND t.b = x.minb
    ORDER BY a

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    How about that ? I guess more efficient, or mybe not.
    Code:
    SUBSTRING_INDEX(group_concat(c order by d),',',1)
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •