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
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
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.
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
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