Click here to Skip to main content
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 7:38am
Edited 2-Jul-13 8: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)



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2014
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