【发布时间】:2018-01-16 19:21:15
【问题描述】:
我有一张桌子table1o_idPK,host,b_id
o_id host b_id
9205 host1.abc.com null
9206 host2.abc.com null
9207 host3.abc.com null
---超过1000行
我有另一张桌子 table2 id PK, hostname, b_id
id hostname o_id ip
18356 host1 null 10.10.10.10
18357 host2 null 10.11.11.11
18358 host3 null 10.12.12.12
---超过1000行
现在,如果hostname(excluding domain name) 在两个表中匹配并且ip 地址在('10.10|10.11') 范围内,那么我想更新两个表,以便table2.o_id = table1.o_id 和table1.b_id = table2.id
update table1 T1
inner join table2 T2 on T2.hostname = substring_index(T1.host, '.', 1)
set T2.o_id = T1.o_id ,
T1.b_id = T2.id
where T1.b_id IS NULL AND
T2.ip IN (select ip from table2 where ip regexp ('10.10|10.11')
limit 10);
在这里,我想从第一个表中的 o_id 更新第二个表中的 o_id。
我还想从第二个表中的id 更新第一个表中的b_id。
在这里,我收到了error
Error Code: 1235. This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
我使用的是 MYSQL Versin 6.0
【问题讨论】:
-
regexp ('10.10|10.11')不代表范围。 '192.169.10.10' 或192.10.11.255或不那么明显的192.210.11呢?
标签: mysql sql join sql-update inner-join