hpr-tools/Database/double_host.sql

19 lines
805 B
SQL

/*---------------------------------------------------------------------------
* Written a while ago. I think it finds hosts called "'host1' and 'host2'"
* and pulls the individual hosts out of the pair so that they can be
* installed into the table as separate hosts
---------------------------------------------------------------------------- */
select ho.hostid, ho.host, n1.hostid, n1.host, n1.host1, n2.hostid, n2.host, n2.host2
from hosts ho
left join (select hostid, host, left(host,instr(host,' and ')-1) as host1
from hosts
where host like '% and %') as n1
on n1.host1 = ho.host
left join (select hostid, host, substring(host,instr(host,' and ')+5) as host2
from hosts
where host like '% and %') as n2
on n2.host2 = ho.host
where n1.host1 is not null
or n2.host2 is not null
;