Click here to Skip to main content
11,638,173 members (79,823 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL
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 2-Jul-13 6:38am
Edited 2-Jul-13 7:25am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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)
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);
  Permalink  
Comments
Maciej Los at 3-Jul-13 15:18pm
   
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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?
  Permalink  

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

  Print Answers RSS
0 jyo.net 348
1 Sergey Alexandrovich Kryukov 314
2 stibee 288
3 OriginalGriff 190
4 Mika Wendelius 185
0 OriginalGriff 9,051
1 Sergey Alexandrovich Kryukov 8,773
2 Mika Wendelius 7,034
3 Suvendu Shekhar Giri 2,425
4 F-ES Sitecore 2,408


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100