I am wondering can you create an array variable in MySQL? I know that you can create a normal variable like so SET @var1 = "myvar";
but is there a way of creating an array? If so how?
Asked
Active
Viewed 2.6k times
7

Marc Delisle
- 8,879
- 3
- 29
- 29

user3144542
- 599
- 3
- 9
- 19
-
1Did you try google? http://stackoverflow.com/questions/12176709/how-can-i-simulate-an-array-variable-in-mysql – Digital Chris Dec 30 '13 at 18:52
-
MySQL does not support arrays. Neither in the procedural language nor as a data type. – Dec 31 '13 at 11:37
1 Answers
15
You can create an array like so
SET @arrayVar = 'var1,var2,bar3,foo4';
It can be used thus
select from myTable where find_in_set(myTable.myColumn, @arrayVar);
If you want to create an array from a query, you can use temporary tables
create temporary table if not exists tmp_table select myColumn from myTable where

Michael Zajac
- 55,144
- 7
- 113
- 138

Igbanam
- 5,904
- 5
- 44
- 68
-
works also on calculated value like : `find_in_set(month(mytable.myDate), @arrayVar)` – yoni Jul 21 '20 at 14:42