我有一个完美的postgresql查询
select "exhibitions_artworks".*, "curator_rating"."curator_id", "curator_rating"."selected",
"curator_rating"."rating", "curator_rating"."submitted" from "exhibitions_artworks"
full outer join "curator_rating" on "curator_rating"."artwork_id" = "exhibitions_artworks"."id"
where "exhibitions_artworks"."exhibition_id" = 15
and "exhibitions_artworks"."exhibition_id" is not null
and "active" = true
and "exhibitions_artworks"."status" = 0
and "curator_rating"."curator_id" = 71 or "curator_rating"."curator_id" is null
我使用laravel,我想重写成laravel查询生成器这个。但laravel orm不支持 full outer join
. 有什么想法吗?
1条答案
按热度按时间5lhxktic1#
在laravel上,如果您想原始编写sql,可以使用
DB:raw
.例子:
SELECT * FROM t1 FULL OUTER JOIN t2 ON t1.id = t2.id;
SELECT * FROM t1 LEFT JOIN t2 ON t1.id = t2.id
UNION ALL
SELECT * FROM t1 RIGHT JOIN t2 ON t1.id = t2.id
$first = DB::table('users')
->whereNull('first_name');
$users = DB::table('users')
->whereNull('last_name')
->union($first)
->get();