Skip to content
Advertisement

Check if any value in list satisfies a condition

Suppose I have the following table called Seasons:

start_month end_month
2 6
3 4

I need to write a query which, for a given list of months, returns all the Seasons that satisfy the condition where at least 1 month in the list is: start_month <= month <= end_month.

I’ve written this query as a native query with JDBC, except the where clause.

JavaScript

I have no idea how to write this, I thought of using the ANY operator until I found out that ANY only works with tables and not lists, I thought of writing this as a subquery with converting the list to a table, but I don’t know if that’s possible, I couldn’t find anything in the MySQL documentation.

Advertisement

Answer

One way to accomplish this is:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement