Making with values of two rows, two entries in a new table.
-
Hi all. I would like to make from three only two rows. I hope someone can helps me to put values which are not "null" to a new row. This is the table which exisits: Table "MACandDNS": NAME | ETH0 | ETH1 | hugo | 000011223333 | 000011223334 | sassy | 000013323333 | 000211223334 | jan | 985555111113 | | kevin |
-
Hi all. I would like to make from three only two rows. I hope someone can helps me to put values which are not "null" to a new row. This is the table which exisits: Table "MACandDNS": NAME | ETH0 | ETH1 | hugo | 000011223333 | 000011223334 | sassy | 000013323333 | 000211223334 | jan | 985555111113 | | kevin |
Maybe something like?
INSERT INTO MACandDNSnew
SELECT NAME, ETH0 AS ETH
FROM firsttable
WHERE ETH0 IS NOT NULL
UNION
SELECT NAME, ETH1 AS ETH
FROM firsttable
WHERE ETH2 IS NOT NULL -
Hi all. I would like to make from three only two rows. I hope someone can helps me to put values which are not "null" to a new row. This is the table which exisits: Table "MACandDNS": NAME | ETH0 | ETH1 | hugo | 000011223333 | 000011223334 | sassy | 000013323333 | 000211223334 | jan | 985555111113 | | kevin |
This is a bit ugly, but it should work. Atleast if I have understood you correct.
SELECT NAME,ETH0 as ETH
FROM MACandDNS
WHERE ETH0 IS NOT NULL
AND ETH1 IS NOT NULL
UNION
SELECT NAME,ETH1 as ETH
FROM MACandDNS
WHERE ETH0 IS NOT NULL
AND ETH1 IS NOT NULLNote that if ETH0 and ETH1 is the same for one name then you get only one row. If that's a problem you can use
UNION ALL
but then the rows for certain won't be unique"When did ignorance become a point of view" - Dilbert
-
This is a bit ugly, but it should work. Atleast if I have understood you correct.
SELECT NAME,ETH0 as ETH
FROM MACandDNS
WHERE ETH0 IS NOT NULL
AND ETH1 IS NOT NULL
UNION
SELECT NAME,ETH1 as ETH
FROM MACandDNS
WHERE ETH0 IS NOT NULL
AND ETH1 IS NOT NULLNote that if ETH0 and ETH1 is the same for one name then you get only one row. If that's a problem you can use
UNION ALL
but then the rows for certain won't be unique"When did ignorance become a point of view" - Dilbert