0

I have table in postgresql with columns District and tehsil. Tehsil names are not unique and tehsil with same name belong to multiple districts. I want to find out the tehsils with same name belonging to different districts..

Tehsil  District

Alot    Ratlam
Alur    Hassan
Alur    Kurnool
Aluva   Ernakulam
Khanapur    Adilabad
Khanapur    Belgaum
Khanapur    Sangli
Khandaghosh Barddhaman
Khandagiri  Khordha

2 Answers 2

1

Try this

select Tehsil from table
group by Tehsil 
having min(District)<>max(District)

To know which district they belong to

select t1.Tehsil, t1.district from table as t1 inner join 
(
select Tehsil from table
group by Tehsil 
having min(District)<>max(District)
) as t2 on t1.Tehsil =t2.Tehsil 
Sign up to request clarification or add additional context in comments.

1 Comment

I also want to find out to which district those tehsils belong..kindly guide
1

Try this way

select Tehsil from table
group by Tehsil 
having count(Tehsil)>1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.