I have the table with name: table witn next recording: +------+-------+ | id | test | +------+-------+ | 1 | 5 | +------+-------+ | 2 | 6 | +------+-------+ | 3 | 6 | +------+-------+ | 4 | 7 | +------+-------+ | 5 | 8 | +------+-------+ | 6 | 9 | +------+-------+ | 7 | 6 | +------+-------+ | 8 | 10 | +------+-------+ | 9 | 7 | +------+-------+ How can i do to count how manny records i have in the field with the name: TEST with values: 5, 6 and 7; Teoreticaly is: SELECT COUNT(*) AS nr FROM table WHERE test = 5 AND test = 6 AND test = 7; but it doesn't work like this. How can i do that? Thanks!!
Use OR in place of AND SELECT test, COUNT(*) AS nr FROM table WHERE (test = 5 OR test = 6 OR test = 7) GROUP BY test; Code (markup):
Better yet: SELECT test, COUNT(*) AS nr FROM table WHERE test in (5,6,7) GROUP BY test; Code (markup):