I’m trying to write my MySQL query, but I’m stuck on this – I have multiple queries from my php to the SQL database:
SET @var := SELECT MAX(first_column)
FROM table;
SELECT @var,
table.second_column
FROM table;
But it returns SQL error. When I use it in phpmyadmin, it works fine. I’ve googled and I saw people use “SET @var = MySQL query” only in stored procedures. Is it possible to use it the way I want?
If you are running multiple queries (i.e., you have a
;in your query), you either need to run it as two separate queries, or use a command likemysqli_multi_query. Themysql_querycommand can only run a single query at a time.See also this related question.