GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   MySql Help (https://gfy.com/showthread.php?t=1075515)

seeme 07-22-2012 09:34 AM

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 :thumbsup

Harmon 07-22-2012 09:37 AM

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

Faggot. Suck a cock.

fris 07-22-2012 11:05 AM

Quote:

Originally Posted by XYZTraffic (Post 19074059)
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 :thumbsup

i left you a few msgs, you can cancel the thing we talked about.

kazymjir 07-22-2012 11:18 AM

Code:

SELECT *
  FROM `items`
  GROUP BY `group`
  ORDER BY RAND();

Selects one random item from each group

seeme 07-22-2012 11:53 AM

Quote:

Originally Posted by kazymjir (Post 19074187)
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.

kazymjir 07-22-2012 12:49 PM

Quote:

Originally Posted by XYZTraffic (Post 19074224)
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();


ShoeBox 07-22-2012 02:31 PM

Quote:

Originally Posted by Harmon (Post 19074062)
I guess your answer lies within gun control in the US. If only there weren't so many gunzzzzzzzzzzzzzzzzzz!

Faggot. Suck a cock.

:1orglaugh

seeme 07-22-2012 03:04 PM

Quote:

Originally Posted by kazymjir (Post 19074285)
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

adultdomainseller 07-22-2012 03:54 PM

Quote:

Originally Posted by Harmon (Post 19074062)
I guess your answer lies within gun control in the US. If only there weren't so many gunzzzzzzzzzzzzzzzzzz!

Faggot. Suck a cock.

:1orglaugh:1orglaugh:1orglaugh


All times are GMT -7. The time now is 11:04 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123