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

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -