Reputation: 20678
I have these Attributes in a table ABC
Location, Zone, Sector, UnitNo
and want to write a query for them where Location and UnitNo are same but Sector is different means I have sectors in different locations where UnitNo is same
I wrote this one but does not work.
select * from ABC A1 Inner JOIN ABC A2 on A1.Id = A2.ID
WHERE
A1.Sector <> A2.Sector AND A1.Location = A2.Location ANd A1.UnitNo = A2.UnitNo
please help.
Upvotes: 1
Views: 78
Reputation: 2415
Please fine the below code
select * from ABC A1 Inner JOIN ABC A2
on A1.Id = A2.ID
and A1.Sector <> A2.Sector
AND A1.Location = A2.Location
ANd A1.UnitNo = A2.UnitNo
Upvotes: 0
Reputation: 18659
I guess you needed the following query
SELECT
*
FROM
YourTable
WHERE
Location=UnitNo AND
Location<>Sector
Upvotes: 0
Reputation: 1990
Try this,
select location, unitno
from abc
group by location, unitno
having count(distinct sector) > 1;
Upvotes: 2