SELECT listings.id,
listings.space_fullname,
images.image_file
FROM listings
LEFT OUTER JOIN images
ON images.id = (SELECT id
FROM images
WHERE images.listings_id = listings.id
LIMIT 1)
WHERE listings.id = 69
如何在不使用DB :: raw或DB :: select?
的情况下以laravel方式执行此查询谢谢
答案 0 :(得分:1)
->I think listings and images are two different tables
->In both tables images.listings_id and listings.id may be equal
然后在查询下面可能有用
DB::table('listings')->leftjoin('images','images.listings_id','=','listings.id') ->select('listings.id','listings.space_fullname','images.image_file')
->where('listings.id','=',69)
->get();