F
F
frontendo2017-05-20 13:09:57
PHP
frontendo, 2017-05-20 13:09:57

Is there a possibility in Laravel using querybuilder to make queries with subqueries?

Compiled such a query, tested in phpmyadmin
SELECT from_id, MAX(id) as updated
FROM (SELECT from_id, id
FROM messages
WHERE to_id = 1
UNION SELECT to_id, id
FROM messages
WHERE from_id = 1
ORDER BY id DESC) as talks
GROUP BY from_id
ORDER BY updated DESC
now it needs to be rewritten via querybuilder
But I didn't find anything similar in the documentation

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DevMan, 2018-08-09
@3dben

description and text are reserved in the muscle.
if you want to use them as column names, then use the backtic: `description` and `text` . Well, this is a kagbe generally accepted rule for avoiding mistakes.

B
Barmunk, 2017-05-20
@frontendo

crap, using DB::raw inside select
https://laracasts.com/discuss/channels/eloquent/se...
itsolutionstuff.com/post/laravel-5-join-with-subqu...

W
wearts_ru, 2017-05-23
@wearts_ru

You can just use selectRaw

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question