【问题标题】:Mysql current version not supporting 'LIMIT & IN/ALL/ANY/SOME subquery'Mysql 当前版本不支持 'LIMIT & IN/ALL/ANY/SOME 子查询'
【发布时间】: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

【问题讨论】:

标签: mysql sql join sql-update inner-join


【解决方案1】:

只需多写一个join 而不是in:

update table1 T1 inner join
       table2 T2 
       on T2.hostname = substring_index(T1.host, '.', 1) join
       (select distinct ip
        from table2
        where ip regexp ('10.10|10.11')
        limit 10
       ) t3
       on t2.ip = t3.ip
set T2.o_id = T1.o_id , 
    T1.b_id = T2.id
where T1.b_id IS NULL ;

【讨论】:

    猜你喜欢
    • 2017-11-14
    • 2015-03-07
    • 2013-07-27
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    相关资源
    最近更新 更多