Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 07-22-2012, 09:34 AM   #1
seeme
Stephen
 
Industry Role:
Join Date: Jun 2011
Location: Europe
Posts: 840
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
seeme is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-22-2012, 09:37 AM   #2
Harmon
( ͡ʘ╭͜ʖ╮͡ʘ)
 
Harmon's Avatar
 
Industry Role:
Join Date: Mar 2004
Posts: 20,007
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]
Harmon is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-22-2012, 11:05 AM   #3
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,359
Quote:
Originally Posted by XYZTraffic View Post
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.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-22-2012, 11:18 AM   #4
kazymjir
Confirmed User
 
kazymjir's Avatar
 
Industry Role:
Join Date: Oct 2011
Location: Munich
Posts: 411
Code:
SELECT *
   FROM `items`
   GROUP BY `group`
   ORDER BY RAND();
Selects one random item from each group
__________________
http://kazymjir.com/
kazymjir is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-22-2012, 11:53 AM   #5
seeme
Stephen
 
Industry Role:
Join Date: Jun 2011
Location: Europe
Posts: 840
Quote:
Originally Posted by kazymjir View Post
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.
seeme is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-22-2012, 12:49 PM   #6
kazymjir
Confirmed User
 
kazymjir's Avatar
 
Industry Role:
Join Date: Oct 2011
Location: Munich
Posts: 411
Quote:
Originally Posted by XYZTraffic View Post
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();
__________________
http://kazymjir.com/

Last edited by kazymjir; 07-22-2012 at 12:51 PM..
kazymjir is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-22-2012, 02:31 PM   #7
ShoeBox
So Fucking Banned
 
Industry Role:
Join Date: May 2012
Location: Brazil
Posts: 2,056
Quote:
Originally Posted by Harmon View Post
I guess your answer lies within gun control in the US. If only there weren't so many gunzzzzzzzzzzzzzzzzzz!

Faggot. Suck a cock.
ShoeBox is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-22-2012, 03:04 PM   #8
seeme
Stephen
 
Industry Role:
Join Date: Jun 2011
Location: Europe
Posts: 840
Quote:
Originally Posted by kazymjir View Post
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
seeme is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-22-2012, 03:54 PM   #9
adultdomainseller
So Fucking Banned
 
Industry Role:
Join Date: Jul 2012
Posts: 155
Quote:
Originally Posted by Harmon View Post
I guess your answer lies within gun control in the US. If only there weren't so many gunzzzzzzzzzzzzzzzzzz!

Faggot. Suck a cock.
adultdomainseller is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.