从sql查询中选择唯一的联系人no,不要检查其他列 [英] select unique contact no from sql query and dont check other columns

查看:124
本文介绍了从sql查询中选择唯一的联系人no,不要检查其他列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cmd = new OleDbCommand("Select distinct contactno,cust_name from table1",con);





我正在使用上面的查询但是当contactno和 cust_name 都相同时,它会检索唯一的记录。我想只使用contactno放置distinct关键字,以便它根据contactno检索记录而不检查 cust_name



I am using query like above but it retrieve unique records when both contactno and cust_name are same.. I want to put distinct keyword only with contactno so that it retrieve records based on contactno and dont check cust_name.

推荐答案

根据我的理解,您似乎必须获取具有相同contactno和cust_name的唯一记录.Above解决方案在这种情况下是完美的。你也可以通过另一种方法来实现这个目标。



As per my understanding it seems you have to fetch unique records those are with same contactno and cust_name .Above solution is perfect in this case .you can achieve this by another method as well..

cmd = new OleDbCommand("select contactno,cust_name from table1 group by contactno,cust_name having count(distinct contactno)=1",con)



但是如果你想删除重复的ContactNo和cust_Name,你可以使用它作为




but if you want to remove duplicated ContactNo and cust_Name you can use it as

cmd = new OleDbCommand("select contactno,cust_name from table1 group by contactno,cust_name having count(contactno)=1",con);


据我所知你的问题是你在以下之后:

From what I understand of your question you are after the following:
cmd = new OleDbCommand("Select distinct contactno from table1",con);



即表1中的不同联系人列表?


I.e. a list of the distinct contactno's that are in table 1?


参考 - DISTINCT只有一个列 [ ^ ]。


这篇关于从sql查询中选择唯一的联系人no,不要检查其他列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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