select * from (image left join upload on image.id=upload.id) left join photo on image.id=photo.id http://www.palmdy.com