Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
cmd = new OleDbCommand("Select distinct contactno,cust_name from table1",con);


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.
Posted
Updated 2-Jul-13 7:25am
v2

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..

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

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

C#
cmd = new OleDbCommand("select contactno,cust_name from table1 group by contactno,cust_name having count(contactno)=1",con);
 
Share this answer
 
Comments
Maciej Los 3-Jul-13 15:18pm    
+5
From what I understand of your question you are after the following:
cmd = new OleDbCommand("Select distinct contactno from table1",con);

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900