我正在使用distinct关键字仍显示重复值 [英] i am using distinct keyword still its showing duplicate values

查看:196
本文介绍了我正在使用distinct关键字仍显示重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT DISTINCT facno,fbalance,fdate from MAINTRAN where MAINTRAN.fbankcode='" & "010" & "'" & _
                                         "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
                                         "and MAINTRAN.fbranchcode='" & "01" & "' "





i使用三个字段s facno,fbalance,fdate但是有三个值我不想显示facno复制但它仍然显示重复facno请帮我解决这个问题。



i used three fields facno,fbalance,fdate but amoung three values i dont want to display facno duplicate but its still displaying duplicate facno please help me to solve this issue.

推荐答案

DISTINCT选择所有列中的值都不同,而不仅仅是第一列。因此,如果您的数据是:

DISTINCT selects values which are different in all columns, not just the first. So if your data is:
id Name  x    y
1  Joe   1    2
2  Joe   1    3
3  Joe   1    3

然后

SELECT DISTINCT [Name], x, y FROM MyTable

将返回:

Will return:

Joe   1    2
Joe   1    3



如果您只想返回Joe中的一行,那么您需要更仔细地思考并确定否则将会是哪一行你感兴趣的相同!

SQL不能这样做 - 它不知道你想要的三个Joe行中的哪一行。


If you want to only return one row with "Joe" in, then you need to think more carefully and decide which of the rows that will be otherwise identical you are interested in!
SQL can't do that - it doesn't know which of the three "Joe" rows you do want.


if你只选择



if you select only

SELECT DISTINCT facno from MAINTRAN where MAINTRAN.fbankcode='" & "010" & "'" & _
                                         "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
                                         "and MAINTRAN.fbranchcode='" & "01" & "' "







你必须得到不同的值,但是为了确保你的另外两列具有不同的值,因此你得到了那种结果。




You must get the distinct values, But for sure your other two column have different values hence you are getting that kind of result.


这篇关于我正在使用distinct关键字仍显示重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆