hi im having trouble with a query and would appreciate any help.
i have tables:
user (username, pic_id, qNum)
images (pic_id, path)
I want to construct a query which returns the users pic_id and 8 other random pic_id 's from the images table not including the one already got from the user table.
i know about ORDER BY RAND() and limiting the result set ... but i cant seem to construct the query properly...
so far i am using ...
SELECT user.user_id,user.pic_id,images.pic_id
FROM user, images
WHERE images.pic_id != '2' // this is the pic in user table
AND user.user_id = '1' // this is the current user
ORDER BY RAND() LIMIT 8
this gives 8 pic_id's from the images table not including the one in the user table.
How can i append the one in the user table to this?
I have tried union but i couldnt fugure that out properly.... do i have to write the 8 to maybe a temp table then add the extra one, them do a select statement on that temp table or is there an easier way??
thanks
i have tables:
user (username, pic_id, qNum)
images (pic_id, path)
I want to construct a query which returns the users pic_id and 8 other random pic_id 's from the images table not including the one already got from the user table.
i know about ORDER BY RAND() and limiting the result set ... but i cant seem to construct the query properly...
so far i am using ...
SELECT user.user_id,user.pic_id,images.pic_id
FROM user, images
WHERE images.pic_id != '2' // this is the pic in user table
AND user.user_id = '1' // this is the current user
ORDER BY RAND() LIMIT 8
this gives 8 pic_id's from the images table not including the one in the user table.
How can i append the one in the user table to this?
I have tried union but i couldnt fugure that out properly.... do i have to write the 8 to maybe a temp table then add the extra one, them do a select statement on that temp table or is there an easier way??
thanks