MySql LEFT JOIN within LEFT JOIN -


i trying following mysql query search box. trying return "album" info (title etc) while including thumbnail of first image in album. however, have 2 tables image info. first, photos_albums contain images in album, first image id table, image info in photos table. believe problem having, need tell first left join limit query 1, have had no luck doing this. think need join within join? on appreciated.

select albums.title, albums.title_url, photos.path, photos.medtype, photos.vpath albums left join photos_albums     on photos_albums.album_id = albums.id left join photos     on photos_albums.photo_id = photos.id albums.user = '$site_user' , (     albums.title '$keyword%'     or albums.title '% $keyword%') limit 6 

you can try this

select a.title, a.title_url, q.path, q.medtype, q.vpath   albums left join  (     select pa.album_id, pa.photo_id, p.path, p.medtype, p.vpath            (         select album_id, min(photo_id) photo_id           photos_albums           group album_id     ) pa join photos p         on pa.photo_id = p.id ) q      on a.id = q.album_id  a.user = '$site_user'    , (          a.title '$keyword%'       or a.title '% $keyword%')  limit 6 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -