从enrich_chat_message
中选择DISTINCT rich_customers.id
INNER JOIN rich_customers ON rich_chat_message.sent_by = enrich_customers.id
|| rich_chat_message.received_by = enrich_customers.id
其中(enrich_chat_message.sent_by = 3
|| rich_chat_message.received_by = 3)和rich_customers.id!= 3
将原始查询转换为雄辩的查询
从enrich_chat_message
内联接中选择DISTINCT rich_customers.id进入rich_chat_message.sent_by = enrich_customers.id || rich_chat_message.received_by = enrich_customers.id其中(enrich_chat_message.sent_by = 3 || rich_chat_message.received_by = 3)和rich_customers.id!= 3
收件人:
DB::table('chat_message')
->select('customers.id')
->JOIN('customers','chat_message.received_by','=','customers.id','||','customers','chat_message.sent_by','=','customers.id')
->where('chat_message.sent_by',3)
->orWhere(function($q) use ($authid){
$q->where('chat_message.sent_by',3)
->orwhere('chat_message.received_by',3);
})->where('chat_message.sent_by','!=', 3)
->distinct()->get();
答案 0 :(得分:1)
DB::table('chat_message') ->JOIN('customers','chat_message.received_by','=','customers.id','||','customers','chat_message.sent_by','=','customers.id')
->select('customers.id')
->where('chat_message.sent_by',3)
->orWhere(function($q) use ($authid){
$q->where('chat_message.sent_by',3)
->orwhere('chat_message.received_by',3);
})->where('chat_message.sent_by','!=', 3)
->groupBy(customers.id)->get();
尝试groupBy而不是与众不同