7

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?

2
  • 1
    Did you try google? stackoverflow.com/questions/12176709/… Commented Dec 30, 2013 at 18:52
  • MySQL does not support arrays. Neither in the procedural language nor as a data type. Commented Dec 31, 2013 at 11:37

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

1 Comment

works also on calculated value like : find_in_set(month(mytable.myDate), @arrayVar)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.