Reply
A sort of select distinct
Old 04-26-2008, 01:01 PM A sort of select distinct
solomongaby's Avatar
Webmaster Talker

Posts: 516
Name: Gabe Solomon
Location: Romania
ok this had me thinking for a while now ... but it seems its beyond my reach so i am asking you guys for help.
So i have a table that holds users pictures and it has this fields basicly:
userID
filename

i want a query that will return 10 diferent pictures from 10 diferent users.
I know it might seem simple for some of you, but my best query was a group by userID, but that will return the same picture for a given user.

TK for answers.
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Sponsored Links (We share ad revenue):
 
Old 04-26-2008, 02:35 PM Re: A sort of select distinct
chrishirst's Avatar
Super Moderator

Posts: 10,642
Location: Blackpool. UK
is the selection to be random or against some criteria? and what DB server?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-26-2008, 02:41 PM Re: A sort of select distinct
Average Talker

Posts: 21
is it like you are trying to fetch first 10 pictures of the users then try using query like.

select top 10 * from tablename

OR are you trying to build pagination on your web page and you want the query should return 10 rows from the database for each page?Then try query like select * from tablename limit 10.
limit 10 will do pagination thing for you but remember you will also need to do some other programming to handle this pagination.

Hope this helps
__________________
What is FTP and how to use FTP Client? - Read Article
Google Analytics Interface Tutorial - Watch Video
technica is offline
Reply With Quote
View Public Profile Visit technica's homepage!
 
Old 04-26-2008, 03:48 PM Re: A sort of select distinct
solomongaby's Avatar
Webmaster Talker

Posts: 516
Name: Gabe Solomon
Location: Romania
my server is mysql.

I am trying to display on the home page of a website 10 random pictures ... but they need to be from diferent users.
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-26-2008, 08:31 PM Re: A sort of select distinct
tripy's Avatar
Fetchez la vache!

Latest Blog Post:
Pretty pretty please….
Posts: 1,689
Name: Thierry
Location: In the void
brm.. I need to sleep, I was writing something totally out of subject... I'll think about it though
__________________
Listen to the ducky: "This is awesome!!!"


Last edited by tripy : 04-26-2008 at 08:36 PM.
tripy is offline
Reply With Quote
View Public Profile
 
Old 04-27-2008, 05:16 AM Re: A sort of select distinct
chrishirst's Avatar
Super Moderator

Posts: 10,642
Location: Blackpool. UK
Ok I would suggest this is better done in code rather than in SQL. Simply because this would really need a SP which your version of MySql may not support.

run a query to get the IDs for the users
use a serverside code loop to get 10 rows at random and concatenate the IDs into a CSV string.

run an IN(csv) query to get those user records

while: (display loop)

show the user details, query the db for all images for that user and select one rownumber at random (>0 <rowcount), show the image.
close the images recordset
move to next user record.
wend:
close userRS
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-27-2008, 06:34 AM Re: A sort of select distinct
solomongaby's Avatar
Webmaster Talker

Posts: 516
Name: Gabe Solomon
Location: Romania
previously i had this code made with a select of random 10 users and the foreach select a random image for each. But i was thinking that i could do it in one query instead of 11 as it is now. But thank you for your reply.
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-28-2008, 07:18 PM Re: A sort of select distinct
Learning Newbie's Avatar
Moderator

Latest Blog Post:
My Favorite Isaac Asimov Story
Posts: 4,070
Name: John Alexander
Quote:
Originally Posted by chrishirst View Post
use a serverside code loop to get 10 rows at random and concatenate the IDs into a CSV string.

run an IN(csv) query to get those user records
Optimized mainframe processing?
__________________
HungarianNotation is the last resort of scoundrels. Why not the first resort? That's where it counts!
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 04-29-2008, 02:54 AM Re: A sort of select distinct
solomongaby's Avatar
Webmaster Talker

Posts: 516
Name: Gabe Solomon
Location: Romania
oh now i understand ... i misunderstood
Thank you verry much for your answers.
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Sponsored Links (We share ad revenue):
 
Reply     « Reply to A sort of select distinct
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML


Page generated in 0.19530 seconds with 14 queries