2017-09-13 59 views
0

我需要在集合中返回分頁,但我只能在數組中返回,因爲查詢使用自然聯接。 我怎麼能做使用Laravel收藏此查詢:LARAVEL MYSQL如何使用自然JOIN

SELECT mensagens * FROM mensagens自然科學JOIN(SELECT id_emissor,MAX(created_at)created_at FROM mensagens WHERE id_receptor = 「$ user_ID的。」 GROUP BY id_emissor)筆

我已經使用這個代碼:

$ mensagem = \ DB ::選擇( DB ::原始(「SELECT mensagens * FROM mensagens自然連接(SELECT id_emissor,MAX(created_at) created_at FROM mensagens WHER E id_receptor =「。$ user_id。」GROUP BY id_emissor)t「) );

+0

檢查:https://stackoverflow.com/questions/22925451/how-can-i-query-raw-via-eloquent –

回答

0

如果你想用你的查詢,因爲它是那麼用這樣的 -

\DB::raw("SELECT mensagens.* FROM mensagens NATURAL JOIN (SELECT id_emissor, MAX(created_at) created_at FROM mensagens WHERE id_receptor = ".$user_id." GROUP BY id_emissor) t"); 

否則,您可以使用口才也。