Click here to Skip to main content
16,019,514 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
query of how to select distinct values from a database.
Posted

Use distinct keyword. Give more details if you want explicit example or code.
 
Share this answer
 
Comments
Member 10578683 7-Apr-14 3:21am    
string qry = "select distinct * from Products";
DataSet ds = du.GetDataSet(qry);
gdvProducts.DataSource = ds;
gdvProducts.DataBind();
Member 10578683 7-Apr-14 3:21am    
here distinct keyword is not working
ArunRajendra 7-Apr-14 3:24am    
If distinct work on combination of fields. Since you have given * it take all the fields from products table and build distinct. If you want distinct of specific field or fields then mention the field names.
ArunRajendra 7-Apr-14 3:24am    
If you could give your requirement and data modal. We can try to build the query.
Member 10578683 7-Apr-14 4:04am    
I have an gridview with two columns ID Product. and a Products database. These are the data of database. I want to populate only distinct product value in gridview.
2 Mouse
3 SMPS
4 Motherboard
5 RAM
6 HDD
7 Processor
8 Monitor (TFT)
9 Mouse Pad
11 Laptop Screen
12 Monitor (CRT)
14 joystick
15 Baterry
21 RAM
22 RAM
NULL NULL
Refer: sql_distinct[^]
 
Share this answer
 
Comments
Member 10578683 7-Apr-14 3:44am    
As in my gridview i have used both ID and Product. How will i use distinct keyword to get distinct product
Member 10378142 7-Apr-14 5:10am    
use
select * from table_name group by ID,product

then you will get a distinct values
Hi
Try this

SQL
Select Distinct Product from Products ORDER BY Product




Regards
Aravind
 
Share this answer
 
v4
Comments
Member 10578683 7-Apr-14 5:22am    
I did like this but an error is coming
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'.
Member 10578683 7-Apr-14 5:37am    
now it is working.Thanks all for helping me

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