Sunday, 8 September 2013

Fetching random rows, along with matching rows from another table?

Fetching random rows, along with matching rows from another table?

I'm trying to get 10 random rows from table 'users', along with the
matching profile picture from table 'Profile_pictures'.
My query so far:
SELECT u.id, u.username, u.status, p.file_name
FROM users AS u, profile_pictures AS p
WHERE p.status = 1 AND u.status != 3 AND u.status != 4
AND RAND()<(SELECT ((1/COUNT(*))*10) FROM users AS u)
GROUP BY u.id
ORDER BY RAND()
LIMIT 7
The problem is that it is getting the same profile picture for all of the
rows.
Have been trying for hours to get this working, so I really, really hope
that you can help me out.
Best, Matt.

No comments:

Post a Comment