【发布时间】:2018-11-15 16:44:04
【问题描述】:
我有一张桌子table1a_idPK,hostname,create_dt
这里ipaddress是varchar,create_dt是datetime
a_id hostname create_dt
9205 abc.com 2017-01-07 08:03:32
9206 cde 2017-01-06 08:03:32
9207 abc2.com 2015-01-07 08:03:32
---超过1000行
我有另一个 mysql 表,其以下列 id 为 PK、name 和 created_dt:
而created_dt 是datetime
id name created_dt
1 abc 2017-01-07 10:03:32
2 cde.com 2017-01-07 10:03:32
3 abc2.com 2016-11-07 10:03:32
4 abc3.com 2016-11-07 10:03:32
5 abc4.com 2017-01-06 10:03:32
6 abc5.com 2015-01-06 10:03:32
我想使用hostname 和name 比较table1 和table2,并从table2 中获取主机名存在于table1 中的所有行
所以从上面的例子中,我的查询应该返回
id name timestamp_val
1 abc 2017-01-07 10:03:32
2 cde.com 2017-01-07 10:03:32
3 abc2.com 2016-11-07 10:03:32
我写了以下查询
SELECT *
FROM table2.name a
INNER JOIN table1.hostname b
where a.name LIKE CONCAT(b.hostname, '%');
【问题讨论】:
标签: mysql join inner-join crud outer-join