Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL
i am using query like below. I dont want to repeat contactno records. Only user with one phoneno should be shown.. i am using query like below but it is giving error like You tried to execute a query that does not include the specified expression 'cust_name' as part of an aggregate function.

 
new OleDbCommand("Select contactno,cust_name,gender,age,address,profession,nationality from table1 group by contactno", con);
Posted 2-Jul-13 4:37am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If the selected fields: contactno, cust_name, gender, age, address, profession, nationality, can be found is multiple records, then you should select DISTINCT records.
 
Select distinct contactno,cust_name,gender,age,address,profession,nationality from table1

 
A group by clause is used if you want an aggregate of a field, ie: min, max, count, etc.
 
Hope that helps,
 
Tim
  Permalink  
Comments
Harpreet_125 at 2-Jul-13 9:52am
   
i was trying to use like this. but it is not retreiving unique contact no records.. i dont know why..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi Friend,
 
I am sure in your record there could be same contactno but there would also difference in other information of respective contactno there must be a data redundancy and to over come to this situation you have to concatenate unmatched records of particular column of respective contactno.
i think this link would be helpfull to you to make a query http://stackoverflow.com/questions/194852/concatenate-many-rows-into-a-single-text-string[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You aren't actually filtering to find records with only one phone number. What you could do is add a having clause like this:
Select contactno,cust_name,gender,age,address,profession,nationality from table1 
group by contactno,cust_name,gender,age,address,profession,nationality
having count(contactno) = 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 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.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