Assign query results to MySQL variable
it should be @
when you are doing in MySQL
.
set @foo := (select * from table1 join table2 where bar = 0 group by id);
You can also try this:
You cant store full table in any variable but you can store column data in any variable using below query.
SELECT GROUP_CONCAT(col1 SEPARATOR '~~~'), GROUP_CONCAT(col2 SEPARATOR '~~~'), ... INTO @foo, @foo2, ...FROM table1 JOIN table2 WHERE bar = 0 GROUP BY id;
or
select col1, col2, ... into @foo, @foo2, ...from table1 join table2 where bar = 0 group by id