mysql group by help

Discussion in 'PHP' started by imvain2, Dec 7, 2007.

  1. #1
    I have a table called bodyname with the below structure:

    Action_Name,Content
    ---------------------
    Records (info shown is just for sample):

    a,asdasdad
    a,3242343244
    v,asdsadsadasd
    v,a444443534535
    c,asdasdsadasda
    c,6y445y45y45y4

    with a single query I would like to pull a random A, V and C

    I have this, but it pulls the same info and just randomizes the order the returned data is in


    select action_name,content from bodyname group by action_name order by rand()
     
    imvain2, Dec 7, 2007 IP
  2. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm a moron, can someone please move this to database forum.

    Thanks
     
    imvain2, Dec 7, 2007 IP
  3. dsnj

    dsnj Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can pull three rows with one query, and then use your code to access one variable from each of the 1st, 2nd, and 3rd rows (which are all randomly selected).
     
    dsnj, Dec 7, 2007 IP
  4. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm sorry but I don't understand what you are saying
     
    imvain2, Dec 8, 2007 IP