I have this kind of mysql db (table name/fields)
tbl_users: id, title, approved
tbl_photos: id, user_id, title, filename
I have one row in users, and three photos (all with user_id = the id of the user)
doing this:
select
tbl_users.*,
tbl_photos.filename
from tbl_users
left join tbl_photos on tbl_photos.user_id = tbl_users.id
where tbl_users = '1' order by rand()
(table query simplified a little bit)
doing that sql query returns three rows . I only want one row (ie i want the user row, plus any random photo that has the user_id of that user id)
i’ve tried all joins – left right inner but they always return 3 rows
Your code should be like the following
The LIMIT keyword will restrict the query for returning only 1 row.
A simple list of my-sql command examples can be found here
http://itswadesh.wordpress.com/2011/04/12/mysql-commands/