设为首页 加入收藏

TOP

SQLServer两个表出现重复数据解决方法
2014-11-24 02:49:42 来源: 作者: 【 】 浏览:1
Tags:SQLServer 两个 出现 重复 数据 解决 方法

假设我有两个表:
表A 表B
字段: a_id 编号 字段: b_id 编号
a_name 名称 b_name 名称
a_class 类别 b_content 主题
a_tel 电话
a_address 地址
说明:表A中 a_class 的外键为:表b中 b_id字段

如果我们需要根据 a_name和a_address 这两个字段进行模糊查询。也许你会写这样的sql语句:
Sql代码
select * from A,B where A.a_class=B.b_id and a_name like %张三% or a_address like %济南%;

这样会出现数据重复的现象。我们需要改成以下语句:
Sql代码
select * from A,B where A.a_class=B.b_id and (a_name like %张三% or a_address like %济南%);
只是加了一对括号而已......

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SQLServer之整体介绍 下一篇删除sqlserver中的sa帐户

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: