My code is:
CREATE TABLE `table_a` (
`id` INT NOT NULL AUTO_INCREMENT,
`value` varchar(255),
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
CREATE TABLE `table_b` LIKE `table_a`;
INSERT INTO table_a VALUES (1, 'A'), (2, 'B'), (3, 'B');
INSERT INTO table_b VALUES (1, 'B');
SELECT value FROM table_a
INNER JOIN table_b
USING (value);
3
Answers
Something like this should just about do it.
I would use aggregation here:
Note that I also used modern explicit inner joins.
You can achieve this by using
group by
. If you select 2 products inIN
, then your count must be2
. And I used ANSI SQL standard syntax for joinssyntax is checked against syntax validator