Basically I have a list of numbers like:
And I want to perform a query like this for each of the previous numbers:
SELECT COUNT(*), field_name FROM my_table WHERE field_name = NUMBER
Where "NUMBER" will be 1, 2 ... 5 in this example. So I expect a result containing 5 rows and 2 columns.
Right now I'm doing the task this way:
(SELECT ... field_name = 1) UNION (SELECT ... field_name = 2 ) ... (SELECT ... field_name = 5)
Is there any alternative way to do this while still using a single query? In particularly I don't like how the last query may become very long as my list of numbers grows.
What if the query to execute would be something like:
SELECT * FROM my_table WHERE field_name > NUMBER
Using the same mechanism as above but this time let's image that this query will return more than 1 row at every execution.
Is there any way to create a single, elegant, query to do this job instead of using "UNION" multiple times?