Linked Questions

Popular Questions

SQL Query - Filter valid & invalid data by few columns

Asked by At

I have a table data shown as below.

enter image description here

You can generate the same by running following script

DECLARE @Temp Table
(
 Id varchar(50),
 Name varchar(50),
 ProductId varchar(50)
)
insert into @Temp values('1','O1','P1');
insert into @Temp values('1','O1','P2');
insert into @Temp values('2','O1','P1');
insert into @Temp values('3','O1','P3');
insert into @Temp values('4','O1','P4');
insert into @Temp values('5','O1','P4');
insert into @Temp values('6','O1','P6')
select * from @Temp

I want two different out put based on below condition

1) Either Id or ProductId are not same

enter image description here

2) Either Id or ProductId are same

enter image description here

What is the best way to do this operation? Appreciate running code for the same so my input can be validate on the same?

Related Questions