Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT * FROM table WHERE field IN(array) - H2 Database

We are trying to select all rows from a table where a specific field has a value that is contained inside an array of values - e.g.

SELECT * FROM table WHERE field IN(array)

The specific use is seeing if the field contains a specific User Group from an array of provided User Groups that the user currently belongs to - e.g.

SELECT * FROM Gadgets WHERE Visibility IN("Everyone", "Registered User", "Site Owner", "Accountant")

Coming up blank on all our searches, so would love some help on this one.

like image 448
Terrence Bull Avatar asked Jul 15 '26 10:07

Terrence Bull


1 Answers

With a bit more digging we found ARRAY_CONTAINS, which would probably be a better answer to the original question - even though we did end up using EXISTS and referencing another table.

We thought it best to throw it in here for anyone else searching on this topic.

like image 169
Terrence Bull Avatar answered Jul 17 '26 16:07

Terrence Bull



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!