Click here to Skip to main content
15,843,031 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);

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,

Share this answer
Harpreet_125 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..
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[^].
Share this answer
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
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