SQL中如何查询两表中的相似记录

来源:百度知道 编辑:UC知道 时间:2024/06/30 08:18:09
我有两个表 sm , tmpsm
sm 字段 content与tmpsm字段 Col001 是相似的
我如何查询出sm中字段content有多少和tmpsm中Col001相似的记录
SM 中的content字段中存放的是文字,tmpsm中Col001字段中存放的也是我的目地是 看看 sm 中有多少和tmpsm相似
是部分相似

insert into ##temptable(totcount) values(select sm.content,tmpsm.Col001 from sm, tmpsm where sm.content like '%'tmpsm.Col001'%');
select count(totcount) from ##temptable;

以上是建一个临时表,将查询结果插入进去,然后第二步在计算临时表里的有多少行!

相似就是不完全相等哈

不知道你说的相似是指两个字段一样还是,只是两个包含的关键字体一样。
方法一
select a.content,b.Col001 from
sm a left join tmpsm b on a.content=b.Col001
方法二
select * from sm where content like '%select Col001 from tmpsm%'

sql="select sm,tmpsm from where sm.content=tmpsm.Col001"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
查询两个表中相同的记录

相似是什么意思?是完全相同还是部分相同?请解释一下