![]() |
|
|
A sort of select distinct |
|
Webmaster Talker
Latest Blog Post:
Cut HTML string without breaking the tags 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. |
|
|
|
| Sponsored Links (We share ad revenue): |
|
|
Re: A sort of select distinct |
|
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 |
|
|
|
|
|
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 |
|
|
|
|
|
Re: A sort of select distinct |
|
Webmaster Talker
Latest Blog Post:
Cut HTML string without breaking the tags 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. |
|
|
|
|
|
Re: A sort of select distinct |
|
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. |
|
|
|
|
|
Re: A sort of select distinct |
|
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 |
|
|
|
|
|
Re: A sort of select distinct |
|
Webmaster Talker
Latest Blog Post:
Cut HTML string without breaking the tags 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.
|
|
|
|
|
|
Re: A sort of select distinct | |
|
Moderator
![]()
Latest Blog Post:
My Favorite Isaac Asimov Story Posts: 4,070
Name: John Alexander
|
Quote:
![]()
__________________
HungarianNotation is the last resort of scoundrels. Why not the first resort? That's where it counts! |
|
|
|
|
|
|
Re: A sort of select distinct |
|
Webmaster Talker
Latest Blog Post:
Cut HTML string without breaking the tags Posts: 516
Name: Gabe Solomon
Location: Romania
|
oh now i understand ... i misunderstood
![]() Thank you verry much for your answers. |
|
|
|
| Sponsored Links (We share ad revenue): |
| Thread Tools | |
|
|
| Webmaster Resources Marketplace: |
| Software Development Company | Webhosting.UK.com |
| Web Templates | Text Link Brokers | Stock Photos |