比较两个几乎相同的sql值

时间:2011-07-25 18:21:20

标签: sql

比较几乎相同的两个sql值。

我知道这很简单,但我想不出怎么做

我想在两个表中的两个值上进行连接或“select where =”。 问题是一个表有一个带扩展名的filname,另一个表有没有扩展名的文件名。我想忽略扩展,只是做我的比较。 我该怎么做?

我有这样的简单。

select thing1, thing2
where tableName.filename=tableName2.fileName
from tableName,tableName2

2 个答案:

答案 0 :(得分:5)

请不要使用多部分from条款。请改用join语法。

假设tableName有扩展名而tableName2没有:

select
    thing1,
    thing2

from tableName tn

join tableName2 tn2 on tn.fileName like tn2.fileName + '.%'

答案 1 :(得分:0)

假设数据库是SQL Server,而tableName2的条目没有文件扩展名,

试试这个:

select thing1, thing2 
from tableName,tableName2 
where tableName.filename LIKE tableName2.fileName  + '%'
相关问题