Table_1
type | description
Error Some description
Success Another description
Table_2
type | description
Error 1 Some description
Error 2 Another description
Error 3 Yet another description
Run Code Online (Sandbox Code Playgroud)
我需要通过type字段连接这两个表,type字段是两个表中的varchar数据类型.问题是由于"错误"与"错误1"或"错误2"不同,当我比较两个字段时,它返回空结果.我试过了:
select * from Table_1 a
left join Table_2 using (type)
select * from Table_2
where type in (select distinct type from Table_1)
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感谢,提前感谢
编辑:当Table_1中的类型包含在Table_2中的类型中时,我应该能够获得结果.我知道它有点难以获得,但问题是在Table_1中我有不同场景的一般错误,而Table_2包含这些相同的错误,但旁边有更多的信息.Table_2充满了来自日志文件的数据,我可以做很多事情.
你的联接应该没问题.第三种方式:
select * from Table_1 a
left join Table_2 b on a.type = b.type
Run Code Online (Sandbox Code Playgroud)
如果您没有得到任何结果,那么type列的值不相等.
更新
鉴于您的注释表明它Table_1.type是子字符串Table_2.type,您可以更改连接运算符:
select * from Table_1 a
left join Table_2 b on b.type LIKE '%' + a.type + '%'
Run Code Online (Sandbox Code Playgroud)
这种做法并不理想.谨慎使用.
| 归档时间: |
|
| 查看次数: |
7054 次 |
| 最近记录: |