I am using MySQL. Let's say I have these two tables:
table 1
+---------+
| product |
+---------+
| 1 |
| 2 |
+---------+
table2
+------+---------+
| name | product |
+------+---------+
| A | 1 |
| A | 2 |
| B | 1 |
| B | 3 |
| C | 1 |
+------+---------+
which are produced using the following code:
CREATE TABLE table1(
product INT
);
CREATE TABLE table2(
name VARCHAR(10),
product INT
);
INSERT INTO table1 VALUES(1);
INSERT INTO table1 VALUES(2);
INSERT INTO table2 VALUES('A', 1);
INSERT INTO table2 VALUES('A', 2);
INSERT INTO table2 VALUES('B', 1);
INSERT INTO table2 VALUES('B', 3);
INSERT INTO table2 VALUES('C', 1);
I would like to produce a table with names from table2, for which its products match all products of table1. In this case, simply
+------+
| name |
+------+
| A |
+------+
That's the name of the retailer for which all products match the ones in the other table.
This is probably something simple that I am failing to see. I have tried inner joins, using all with a subquery, ... but...