Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 query builder not supporting more than one table in "from" clause

Is there a way to generate an SQL query in Laravel 4 (using the query builder) which supports more than one table in the "from" clause, without using joins?

I want to make something like this:

SELECT * FROM table_1 as t1, table_1 as t2...

Can this be done without using joins? I noticed that the from() method strips anything after the table name/alias:

->from('table_1 as t1, table_1 as t2')

becomes (yes, with the comma at the end):

table_1 as t1,

Thanks for any help at all.

like image 537
Fen Avatar asked Jul 25 '13 21:07

Fen


1 Answers

The OP answered and updated his question. To make it clearer the answer is:

Antonio Carlos Ribeiro - thanks for the answer, but as I posted in the question, I was trying to avoid using joins, since I have a complex query ready but it does not use joins (and there is a reason for that).

I managed to get it done on my own :) Actually, this was quite simple after all... All I had to do is use DB:raw() which allows to inject a non-formatted portion of the query:

->from(\DB:raw('table_1 as t1, table_1 as t2'))
like image 193
ajtrichards Avatar answered Sep 21 '22 18:09

ajtrichards