MySql Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seeme
    Stephen
    • Jun 2011
    • 840

    #1

    MySql Help

    Ok I have the following tables, what I want to do is select 1 random item from ITEMS for each group in GROUPS. If possible done in 1 query.

    ITEMS
    ID - NAME - DESCRIPTION - GROUP

    GROUPS
    ID - TITLE - STATUS


    Thanks
  • Harmon
    ( ͡ʘ╭͜ʖ╮͡ʘ)
    • Mar 2004
    • 20012

    #2
    I guess your answer lies within gun control in the US. If only there weren't so many gunzzzzzzzzzzzzzzzzzz!

    Faggot. Suck a cock.
    [email protected]

    Comment

    • fris
      Too lazy to set a custom title
      • Aug 2002
      • 55679

      #3
      Originally posted by XYZTraffic
      Ok I have the following tables, what I want to do is select 1 random item from ITEMS for each group in GROUPS. If possible done in 1 query.

      ITEMS
      ID - NAME - DESCRIPTION - GROUP

      GROUPS
      ID - TITLE - STATUS


      Thanks
      i left you a few msgs, you can cancel the thing we talked about.
      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

      Comment

      • kazymjir
        Confirmed User
        • Oct 2011
        • 411

        #4
        Code:
        SELECT *
           FROM `items`
           GROUP BY `group`
           ORDER BY RAND();
        Selects one random item from each group
        http://kazymjir.com/

        Comment

        • seeme
          Stephen
          • Jun 2011
          • 840

          #5
          Originally posted by kazymjir
          Code:
          SELECT *
             FROM `items`
             GROUP BY `group`
             ORDER BY RAND();
          Selects one random item from each group
          When I refresh the query I still get the same item from each group... just that the final list of items is ordered randomly.

          Comment

          • kazymjir
            Confirmed User
            • Oct 2011
            • 411

            #6
            Originally posted by XYZTraffic
            When I refresh the query I still get the same item from each group... just that the final list of items is ordered randomly.
            Ahhhh, true.

            Try this:
            Code:
            SELECT * 
               FROM (SELECT * FROM `items` ORDER BY RAND()) x
               GROUP BY x.group
               ORDER BY RAND();
            Last edited by kazymjir; 07-22-2012, 11:51 AM.
            http://kazymjir.com/

            Comment

            • ShoeBox
              So Fucking Banned
              • May 2012
              • 2056

              #7
              Originally posted by Harmon
              I guess your answer lies within gun control in the US. If only there weren't so many gunzzzzzzzzzzzzzzzzzz!

              Faggot. Suck a cock.

              Comment

              • seeme
                Stephen
                • Jun 2011
                • 840

                #8
                Originally posted by kazymjir
                Ahhhh, true.

                Try this:
                Code:
                SELECT * 
                   FROM (SELECT * FROM `items` ORDER BY RAND()) x
                   GROUP BY x.group
                   ORDER BY RAND();
                Thanks thats what I needed

                Comment

                • adultdomainseller
                  So Fucking Banned
                  • Jul 2012
                  • 155

                  #9
                  Originally posted by Harmon
                  I guess your answer lies within gun control in the US. If only there weren't so many gunzzzzzzzzzzzzzzzzzz!

                  Faggot. Suck a cock.

                  Comment

                  Working...