---
title: "compare two fields of a single table in oracle sql"  
description: "compare two fields of a single table in oracle sql"  
author: "Mark Devid"  
published: 2013-05-09  
updated: 2013-05-09  
canonical: https://www.mindstick.com/forum/841/compare-two-fields-of-a-single-table-in-oracle-sql  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# compare two fields of a single table in oracle sql

Hi All!\
I'm having a [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) like below, I need to write a [sql query](https://www.mindstick.com/forum/529/rename-table-name-and-column-name-using-sql-query) to [compare](https://www.mindstick.com/forum/2036/propertyinfo-getvalue-unable-to-compare-datetimes) and [validate](https://www.mindstick.com/forum/1490/what-is-better-solution-for-validate-form-textboxs-value) the [records](https://www.mindstick.com/forum/34640/how-to-create-a-stored-procedure-for-display-all-records) are in proper order. ex: US is having no1 in column2 like that each \
country have their own no's , I need to write a code to validate that no country has the same no's assigned for more than [one country](https://www.mindstick.com/news/2309/chinese-rocket-falls-to-earth-stopping-air-traffic-in-one-country) and need to [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) [weather](https://yourviews.mindstick.com/view/139/changing-weather-is-this-only-tip-of-an-ice-berg) the country has his assigned no only.\
My table [structure](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) as per following\
| column1 | column2 |--------------------------------| US | no1 || Japan | no2 || dravid | no3 |\
Please help me as soon as possible.\

## Replies

### Reply by AVADHESH PATEL

Hi Mark!\
Try as following\
SELECT column2, COUNT(*) TotalCountFROM YourTableGROUP BY column2HAVING COUNT(*) > 1ORDER BY COUNT(*) DESCwhere TotalCount returns the count of number assigned multiple times. or\
select * From( SELECT distinct Column1, Column2, COUNT(*) over (partition by Column2) TotalCount FROM YourTable)x where TotalCount>1\
I hope it resolve your problem


---

Original Source: https://www.mindstick.com/forum/841/compare-two-fields-of-a-single-table-in-oracle-sql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
