Mysql query matches multiple values in a single field

The

table is roughly as follows:
id sample
1 a
2 b
3 a
4 c
5 d
6 c

Select the count of the sample grouping of id=3,4 (specified field)

   select count(sample) from table where id=3 or id=4 group by sample

the current problem is that if you want to query too many id values, the query statement will be very long, and if the table is large, the rate will be very slow. I would like to ask if there is a better operation. Thank you

.
Apr.11,2021

For continuous cases, use BETWEEN , such as

SELECT COUNT(sample) FROM table WHERE id IN (<id>) GROUP BY sample
Menu