0

I am having a query, which I kept inside a variable, Its working fine when only one result is available, for more than one results, its showing below error

#1242 - Subquery returns more than 1 row.

Can anyone tell me, how to get multiple result set in a MySQL variable

My query is

SET @v1 = (SELECT id FROM `employee` where DATE_ADD(last_active_date, INTERVAL 1 DAY) AND DATE_ADD(last_active_date, INTERVAL 1 DAY)=CURRENT_DATE AND employee_group!=3);

SELECT @v1;
Syscall
  • 19,327
  • 10
  • 37
  • 52
Chitrasen
  • 49
  • 1
  • 6
  • You can't , unless you group_Concat which may make @v1 useless..A temporary table may be appropriate – P.Salmon Feb 10 '22 at 09:09
  • Or a cursor in a stored procedure. Or return the results in json and use json_table() to turn the results into a proper table in the second select. – Shadow Feb 10 '22 at 09:18
  • There is table valued variable in MSSQL so it is possible, but not on MySQL, instead you may use temporary table: https://stackoverflow.com/questions/1524858/create-table-variable-in-mysql/1524918 – endo64 Feb 10 '22 at 09:59
  • Thanks for the suggestions, I will try – Chitrasen Feb 11 '22 at 04:25

0 Answers0