[英]What is the best way to handle this sub query in laravel using DB:raw?
After several attempts I am having trouble getting this raw query formatted using DB::raw in laravel.经过几次尝试,我无法在 laravel 中使用 DB::raw 格式化这个原始查询。 Could someone point me in the right direction?
有人能指出我正确的方向吗? I am trying to avoid using DB::table or spliting it up into multiple queries if possible.
如果可能,我试图避免使用 DB::table 或将其拆分为多个查询。
select id
from ParticipantDetail
where testId= (
select testId from PacketDetail where PacketDetail.packetid=ParticipantDetail.packetid and [order]='1'
)
and packetid = (
select packetid from ParticipantDetail where id = '1f4716e9-6e8b-41ce-b746-60a013fab38f'
)
and masterid = (
select masterid from ParticipantDetail where id = '1f4716e9-6e8b-41ce-b746-60a013fab38f'
)
I think there is no need to make these sub-queries我认为没有必要进行这些子查询
I changed the query a little bit.我稍微改变了查询。 and used DB::select() to run it.
并使用 DB::select() 运行它。
DB::select("select partDtl.id from ParticipantDetail partDtl
INNER JOIN PacketDetail packDtl on packDtl.packetid = partDtl.packetid
WHERE partDtl.id = ? and packDtl.order = ?",
['1f4716e9-6e8b-41ce-b746-60a013fab38f', '1']);
I hope it will work.我希望它会奏效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.