I have some complex SQL which consists of a series of non-query statements, that make use of temporary tables in MySql, and then a SELECT statement at the end to return the result.
e.g
DROP TABLE IF EXISTS temp_foo;
CREATE TEMPORARY TABLE IF NOT EXISTS temp_foo AS (
SELECT *
FROM foo
);
SELECT * from temp_foo;
How can I run this all in the one DB call from Laravel and get the results of that last SELECT statment?
I've tried doing something like this in laravel, but it gives me a MySql syntax error, which is strange as that exact sql works ok when I run it directly in MySQl.
DB::select("
DROP TABLE IF EXISTS temp_foo;
CREATE TEMPORARY TABLE IF NOT EXISTS temp_foo AS (
SELECT *
FROM foo
);
SELECT * from temp_foo;
");
Any ideas on how can make this work?