Table A
Col1 Col2
101 102
101 103
102 104
104 105
Table B
Col1
101
102
103
104
105
I want to take data from Table A and insert it into Table B as a Distinct value in one query
so INSERT INTO TableB (Col1) (SELECT ...)
Any ideas?
Table A
Col1 Col2
101 102
101 103
102 104
104 105
Table B
Col1
101
102
103
104
105
I want to take data from Table A and insert it into Table B as a Distinct value in one query
so INSERT INTO TableB (Col1) (SELECT ...)
Any ideas?
You should be able to do:
INSERT INTO TableB (Col1)
(SELECT Col1 FROM TableA
UNION
SELECT Col2 FROM TableA)
INSERT TABLEB (Col1)
SELECT Col1 FROM TABLEA
UNION SELECT COL2 FROM TABLEA
For non-distinct, UNION ALL
You could easily use two queries like this:
INSERT INTO `TableB` (`Col1`)
SELECT `Col1` FROM `TableA`
INSERT IGNORE INTO `TableB` (`Col1`)
SELECT `Col2` FROM `TableA`