SQL 一个用户资料表一个作品表 ,两个关联的表多个重复mysql 字段关联有好不好呢,

sqlserver中,一个表里面有多个字段,怎样根据两个不能重复的字段取出全部的字段。_百度知道
sqlserver中,一个表里面有多个字段,怎样根据两个不能重复的字段取出全部的字段。
表中的数据,两个字段完全相同的记录我只取其中一条,但是还要全部取出其他可以不唯一的字段。
提问者采纳
select distinct * from table(表名) where (条件)2.存在两条完全相同的纪录
这是最简单的一种情况,用关键字distinct就可以去掉
example,:select identity(int1.没有唯一键ID
这种情况我觉得最复杂..])3.存在部分字段相同的纪录(有主键id即唯一键)
如果是这种情况的话用distinct是过滤不了的.,1) as id.,这就要用到主键id的唯一性特点及group by分组
example,,目前我只会一种方法.: select * from table where id in (select max(id) from table group by [去除重复的字段名列表,有那位知道其他方法的可以留言..,交流一下,* into newtable(临时表) from table select * from newtable where id in (select max(id) from newtable group by [去除重复的字段名列表有重复数据主要有一下几种情况:希望可以帮到你~1
不是的,可能是我表达不够清楚,图片里面我电话和学生姓名这两项都相同的话,我就取id号最大的一条。并且要把其他的字段也取出来。
select * from table where id in (select max(id) from table group by 电话和姓名) 你试试看
提问者评价
谢谢哈,呵呵,您会有好运的,问题解决了。
其他类似问题
为您推荐:
其他2条回答
如果表中的所有字段数据出现一样的二条记录:select distinct * from 表 这个和唯一标示符有关系,你的表设计肯定不不和业务。
select * from 表名 as t where not exists(select 1 from 表名 where 重复字段=t.重复字段 and id&t.id)
sqlserver的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁SQL数据表两个字段关联同一张数据表
数据表temp结构
-- Table &temp& DDL
CREATE TABLE `temp` (
`page_id` bigint(20) DEFAULT NULL,
`section_id` bigint(20) DEFAULT NULL,
`visit_category_id` bigint(20) DEFAULT NULL,
`cart_category_id` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;数据表category结构
-- Table &category& DDL
CREATE TABLE `category` (
`category_id` bigint(20) DEFAULT NULL,
`category_name` varchar(128) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
关联temp表和category表,取出visit_category_id和cart_category_id对应的category_name
select a.page_id,
a.section_id,
a.visit_category_id,
b.category_name,
a.cart_category_id,
c.category_name
from temp a
left outer join category b on (a.visit_category_id=b.category_id)
left outer join category c on (a.cart_category_id=c.category_id);查询结果
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'SQL 中同一个表中有多个字段有重复值,该如何筛选_百度知道
SQL 中同一个表中有多个字段有重复值,该如何筛选
baidu:///zhidao/pic/item/902397dda144ad3472aaf20ed2a20cf431ad8525.baidu.hiphotos,C两列的值类型一样://d.com/zhidao/wh%3D600%2C800/sign=abeb1354492bfbd962e84eb/902397dda144ad3472aaf20ed2a20cf431ad8525.baidu,反正就是A列本身与B列本身都不能含有这两列公共的值,该如何筛选.com/zhidao/wh%3D450%2C600/sign=a9a3e6a7aad3fd1f365caa3e057edda144ad3472aaf20ed2a20cf431ad8525在一个表中存在以上数据,B,A列有哪些重复的值://d,如今想找出.jpg" esrc="http.,及A列与B列相同的值。请高手解答..hiphotos
我有更好的答案
or a in (select a from table a,table b where a.a =bselect A from
table where a
in(select A from table group by A having count(*)&gt
这不是我想要的结果,不过还是谢谢你了。
奇怪,不是找a中重复和b中相同的值吗?
在同一个表
是啊!可以自连接啊!
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁sql 中如何删除其中一个表中跟另一个表字段内容重复的行?_百度知道
sql 中如何删除其中一个表中跟另一个表字段内容重复的行?
如果是删除单个字段重复可用in,如果是删除多个字段重复可用exists。如表1数据:id & & & &name & & & & &age1 & & & & &张三 & & & & & & 192 & & & & &李四 & & & & & & 203 & & & & &王五 & & & & & & 174 & & & & &赵六 & & & & & & 21表2数据:id & & & &name & & & & &age1 & & & & &张三 & & & & & & 192 & & & & &李四 & & & & & & 215 & & & & &王五 & & & & & & 14如果删除表1中id和表2相同的内容:delete&from&表1&where&id&in&(select&id&from&表2)如果删除表1中id,name和age都与表2相同的数据delete&from&表1&where&exists&(select&1&from&表2&where&表1.id=表2.id&and&表1.name=表2.name&and&表1.age=表2.age)
为您推荐:
提问者采纳
email = b.email in (
select a.username delete from a where a.email from a, b where a.email and a!= b
提问者评价
原来是这样,感谢!
其他4条回答
email from ainner join bon a.username&lt不知道什么数据库delete from a where email in(&gt.email=b;b.emailwhere a
用in的话性能很差的,可以用delete from a inner join b on a.email=b.email where a.username && b.username
delete from a a where a.email in (select email from b)
delete from a a where a.email =(select email from b)
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}

我要回帖

更多关于 关联字段 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信