Wednesday, 11 September 2013

Joining 2 tables in which the common row has different data formats

Joining 2 tables in which the common row has different data formats

i have 2 tables in my database, one is tablea, and the other is tableb.
select *
from tablea
results in
ip mac
1.10.0.0.97 00 14 2A 2F 72 FE
1.10.0.0.98 08 CC 68 71 A1 C0
select * from tableb
results in
mac port
0:14:2a:2f:72:fe 24
8:cc:68:71:a1:c0 7
I now want to create a third table , which joins tablea and table c and
has 3 columns displaying ip,mac and port. the table has already been
created and this is what i have in mind;
INSERT INTO tablec
SELECT a.ip,a.mac,b.port
FROM tablea a,tableb b
WHERE a.mac=replace('replace('b.mac',':',' ')','0','00')
The query gives me an error
ERROR 1064(42000): You have an error in your SQL syntax; check the manual
that corresponds to your mysql server version for the right syntax to use
near 'b.mac',':',' ')','0','00')
I have checked the manual and i could not identify where my error is . And
also my replace function can be able to convert 0:14:2a:2f:72:fe to 00 14
2A 2F 72 FE but it will not work if tried for 8:cc:68:71:a1:c0. I would
really appreciate any help i can get in creating this 3rd table

No comments:

Post a Comment