读书人

inner join 中 like 的查询如何表达

发布时间: 2012-02-20 21:18:24 作者: rapoo

inner join 中 like 的查询怎么表达?
INNER JOIN topic ON topic.sort_id LIKE '%sort_sort.id%'

这样写不对,因为 '%sort_sort.id%' 中的 sort_sort.id 变成了字符串

INNER JOIN topic ON topic.sort_id LIKE '%"& sort_sort.id &"%'
而一般的这样写也不对,因为 sort_sort.id 没有赋予其变量名。。。。

应该怎么写呢????

[解决办法]
on 后面要跟=的

SQL code
on topic.sort_id = sort_sort.id
[解决办法]
探讨
INNER JOIN topic ON topic.sort_id LIKE '%sort_sort.id%'

这样写不对,因为 '%sort_sort.id%' 中的 sort_sort.id 变成了字符串

INNER JOIN topic ON topic.sort_id LIKE '%"& sort_sort.id &"%'
而一般的这样写也不对,因为 sort_sort.id 没有赋予其变量名。。。。

应该怎么写呢????

[解决办法]
SQL code
INNER JOIN topic ON topic.sort_id LIKE '%'+ltrim(sort_sort.id)+'%' 

读书人网 >SQL Server

热点推荐