How to get unique values from specific column in SQL Server? -
i have table
tblfruit_id tblfruit_fruittype tblfruit_fruitname -------------------------------------------------- 1 citrus orange 2 citrus lime 3 citrus lemon 4 seed cherry 5 seed banana
i can't set distinct tblfruit_fruittype
column only, , if use group by
(i want count function), getting error.
my expected output:
tblfruit_id tblfruit_fruittype tblfruit_fruitname ------------------------------------------------------ 1 citrus orange 4 seed cherry
use window function
;with cte (select row_number()over (partition tblfruit_fruittype order tblfruit_id) rn, * tablename) select tblfruit_id, tblfruit_fruittype, tblfruit_fruitname cte rn = 1
Comments
Post a Comment