|
Posted by Erland Sommarskog on 10/01/37 11:19
(medhanush@yahoo.com) writes:
> Can sb pl help to what t-sql query to use to achieve as follows,
> for some reason, there are duplicate rows, but i need to get
> top most rows of category A, B as follows.
>
> Num Category ProductName
> ---- -------- -----------
> 100 A Product1
> 100 B Product1
>
> 101 A Product2
> 101 B Product2
>
> 102 A Product3
> 102 B Product3
There is no such thing as a "top-most" row in a table. A table is an
orderd set.
It seems that with the sample data you have given that this would do:
SELECT DISTINCT Num, Category, ProductName
FROM tbl
WHERE Category IN ('A', 'B')
If product names are different, you can do:
SELECT Num, Category, MAX(ProductName)
FROM tbl
WHERE Category IN ('A', 'B')
GROUP BY Num, Category
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Navigation:
[Reply to this message]
|