Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



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

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
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:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
 
Register now for full access!
Old 04-26-2008, 03:35 PM Re: A sort of select distinct
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
is the selection to be random or against some criteria? and what DB server?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-26-2008, 03:41 PM Re: A sort of select distinct
Average Talker

Posts: 22
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
- Win $5 every week on the forum

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
technica is offline
Reply With Quote
View Public Profile Visit technica's homepage!
 
Old 04-26-2008, 04:48 PM Re: A sort of select distinct
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
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:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-26-2008, 09:31 PM Re: A sort of select distinct
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
brm.. I need to sleep, I was writing something totally out of subject... I'll think about it though
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 04-26-2008 at 09:36 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-27-2008, 06:16 AM Re: A sort of select distinct
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-27-2008, 07:34 AM Re: A sort of select distinct
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
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:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-28-2008, 08:18 PM Re: A sort of select distinct
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
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?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 04-29-2008, 03:54 AM Re: A sort of select distinct
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
oh now i understand ... i misunderstood
Thank you verry much for your answers.
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Reply     « Reply to A sort of select distinct
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.34626 seconds with 12 queries