SELECT
firstTable.Product,
firstTable.geographies
FROM
(
SELECT
Product,
REPLACE(GROUP_CONCAT(Geography),' ','') AS geographies
FROM T1
GROUP BY Product) firstTable
INNER JOIN
(
SELECT
Product,
REPLACE(Geography,' ','') AS geographies
FROM T2 ) secondTable
ON firstTable.Product = secondTable.Product
WHERE firstTable.geographies = secondTable.geographies;
Note: I've replaced the spaces using REPLACE function just to ensure the two queries from two tables generate the same string
SQL FIDDLE DEMO
TEST (If you cannot access sqlfiddle):
DROP TABLE IF EXISTS `t1`;
CREATE TABLE `t1` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Product` varchar(50) CHARACTER SET utf8 NOT NULL,
`Geography` varchar(100) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`ID`)
);
INSERT INTO `t1` VALUES ('1', 'P1', 'G1');
INSERT INTO `t1` VALUES ('2', 'P2', 'G1');
INSERT INTO `t1` VALUES ('3', 'P2', 'G2');
DROP TABLE IF EXISTS `t2`;
CREATE TABLE `t2` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Product` varchar(50) CHARACTER SET utf8 NOT NULL,
`Geography` varchar(100) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`ID`)
);
INSERT INTO `t2` VALUES ('1', 'P1', 'G1, G2');
INSERT INTO `t2` VALUES ('2', 'P2', 'G1, G2');
Running the above query on this test data you will get output like below:
Product geographies
P2 G1,G2