Select distinct rows only and also remove the distinct rows tied with anyother records.

HI Team,
I need query on below requirment:
In my table any value comes with UN in one field alone, i need to select that row. but UN value comes with anyother row i want to reject that UN row.
For example:
EmployeeID
Name
Speciality
1
John
UN
1
John
KH
2
Mony
UN
3
Kash
UN
3
Kash
UI
I need a Final result
1 John KH
2 Mony UN
3 Kash UI. Need to reject UN value combined with anyother row aand also If any row comes with UN value alone need to incude resultset.

One more option:
declare @tabl table(EmployeeID int,Name varchar(10),Speciality varchar(10));
insert into @tabl values
(1 ,'John','UN'),
(1 ,'John','KH'),
(2 ,'Mony','UN'),
(3 ,'Kash','UN'),
(3 ,'Kash','UI'),
(4 ,'Cat','UN'),
(4 ,'Cat','UT');
with cte as (SELECT *,
count(case when Speciality ='UN' then NULL else 1 end) OVER (PARTITION BY EMployeeID,Name,Speciality ) AS RN1,
count(case when Speciality ='UN' then NULL else 1 end) OVER (PARTITION BY EMployeeID,Name ) as rn2
FROM @tabl)
select EmployeeID,Name,Speciality from cte where RN1=rn2

Similar Messages

Maybe you are looking for

  • Manipulating java array object in an oracle procedure

    hi there, i have a java store procedure that returns an array of filenames, and i have an oracle stored procedure that will for each filename returned in the java array object, open that file do some processing and load the data into database tables,

  • Reports 2.01 Variance Error

    I have a report that uses accounts in the page dimension (with UDAs). When I use the variance function in a column formula I receive a cell error. Why?I have product in the rows & ,years & months in the columns I'm try to compare current month to pri

  • How can I change my database options after it's created ?

    Hi , I'm using a 10 g oracle on a solaris 10 machine .I created a database and now I m willing to change the database option.I tried to use dbca but the Configuration Options checkbox is disabled.Is there any other way to change the database option ?

  • [SOLVED] Cannot install KDE with python-numpy pre-installed?

    Hi, all I am with xfce currently and though of tring KDE. However when I  tried to install KDE it turns that there are confilicts between 'kde' and 'python-numpy': :: Proceed with installation? [Y/n] (318/318) checking keys in keyring [##############

  • No sound Since I upgrade to 2.6.24-1

    Since I run pacman -Syu a few days before, now my machine has no sound. Before I upgrade the whole system, everything goes well. After I upgrade the whole system, the sound doesn't work. Modules have loaded, alsamixer OK, but still no sound . my mach