I've tested and it doesn't select the duplicate values, anyway try it like this:
(SELECT
`field1` as `temp`
FROM `table`
GROUP BY `field1`)
UNION DISTINCT
(SELECT
`field2` as `temp`
FROM `table`
GROUP BY `field2`)
If it still get duplicate values, please attach an sql file to this thread so I can test it on your table or an equivalent table ...
My testing table is like this:
CREATE TABLE `table` (
`field1` int(11) NOT NULL default '0',
`field2` int(11) NOT NULL default '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Salvarea datelor din tabel `table`
--
INSERT INTO `table` VALUES (1, 2);
INSERT INTO `table` VALUES (3, 4);
INSERT INTO `table` VALUES (4, 3);
INSERT INTO `table` VALUES (2, 1);
INSERT INTO `table` VALUES (1, 5);
INSERT INTO `table` VALUES (2, 5);
INSERT INTO `table` VALUES (3, 6);
One question, does your fields the same type?
bradgrafelman wrote:If I'm understanding you correctly, there shouldn't be any need for UNIONs...
SELECT `field1`, `field2`
FROM `table`
GROUP BY `field1`, `field2`
This was my first answer too, but the client has the last words ... 😃