Friday, August 19, 2011

Getting distinct column with multiple columns

if we have table id, name, age


the requirements is id has different and redundatnt data


We want the distinct column with corresponding rows. this is highly useful


SELECT id,
role_id_fk,
privilege_id_fk
FROM (SELECT id,
role_id_fk,
privilege_id_fk,
Row_number() OVER(PARTITION BY role_id_fk ORDER BY id) rn
FROM tbl_roles_privileges) t
WHERE rn = 1