How to make query to the database, if the number of cases is not known in advance?

Develop functionality that extends, e.g. only 1st or only 2nd test questions by subject (anatomy, histology, physiology, etc.)

The issues are thus
SELECT * FROM `tests_new` WHERE `num_q` = 1 AND `var_id` = 1 OR `num_q` = 1 AND `var_id` = 2 OR `num_q` = 1 AND `var_id` = 3


For different objects different number of options (var_id). Stopped me that the advance could not prepare query - one test subject 10, and on another 100. Tell me how to optimize this query.
March 12th 20 at 08:08
1 answer
March 12th 20 at 08:10
$var_id_array = [1, 2, 3, 4, 5, 6];
$query = "SELECT * FROM tests_new WHERE num_q = 1 AND var_id IN (".join(',', $var_id_array).")";

Find more questions by tags MySQL