3
Answers

how to show one row where there is 2 row with same id

prabha haran

prabha haran

7y
244
1
hi
pls give idea that i selected some field from db i have few rows with same stockcode and i have to show only one in grid
 
my code is
 
string qry = "SELECT T1.SRCode,T1.SRDate,T1.Status,T2.Quantity,T2.Price,T2.NetAmount,T3.ProductCode,T3.ProductName FROM Tbl_ReceiveStock T1 INNER JOIN Tbl_ReceiveStockProducts T2 ON T1.SRId = T2.SRId INNER JOIN Tbl_Product T3 ON T2.ProductId = T3.ProductId "; 
Answers (3)
0
Ranjeet Patra

Ranjeet Patra

NA 1.9k 124.9k 7y
Try this one out:
 
string qry = "SELECT  distinct T1.SRCode,T1.SRDate,T1.Status,T2.Quantity,T2.Price,T2.NetAmount,T3.ProductCode,T3.ProductName FROM Tbl_ReceiveStock T1 INNER JOIN Tbl_ReceiveStockProducts T2 ON T1.SRId = T2.SRId INNER JOIN Tbl_Product T3 ON T2.ProductId = T3.ProductId ";
 
Accepted
0
Tapan Patel

Tapan Patel

NA 8.1k 100.8k 7y
If you don't care about the other column data then you can use Row_Number function over your stockID column and get the rows which have row_number as 1 or you can use group by and aggregation over possible columns you want.
If you do care about other columns and data from another tables ( means - if you want to show the data from both the rows ), then there is no way to display it in one line.  
0
Amit Gupta

Amit Gupta

NA 16.5k 25.5k 7y
You can use group by clause to group the result set by one or more column Check below link for reference https://www.w3schools.com/sql/sql_groupby.asp