Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Comparing values in different rows

I need some advice regarding comparing values in different rows in the same table. For example:

```Table X has columns A, B and C:
A B C
1 2 3
1 4 5
```
What I mean by comparison is that the values of B and C need to be reported (their values being non-equal).

As with most SQL questions, there are multiple ways to solve the problem. This one is no different. One way to do it would be to use an EXISTS predicate. First let's create and populate your table.

```create table X
( A number,
B number,
C number
);

insert into X values (1, 2, 3);
insert into X values (1, 4, 5);
insert into X values (2, 6, 6);
insert into X values (2, 6, 6);
insert into X values (3, 1, 7);
insert into X values (3, 1, 9);
insert into X values (4, 8, 0);
```
If I understand your scenario correctly, you wish to only show those rows where the values in columns B and C don't match the values in columns B and C for other rows having the same value for column A. Here's a solution using EXISTS:
```select * from X t
where exists ( select * from X
where A = t.A
and ( B != t.B or C != t.C ) );
```

#### For More Information

• What do you think about this answer? E-mail the edtiors at editor@searchDatabase.com with your feedback.
• The Best SQL Web Links: tips, tutorials, scripts, and more.
• Have an SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
• Ask your technical SQL questions -- or help out your peers by answering them -- in our live discussion forums.
• Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.

This was last published in March 2002

#### Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

#### Start the conversation

Send me notifications when other members comment.

## SearchDataManagement

• ### Hortonworks cloud options grow via Google, Microsoft, IBM

Hortonworks now supports Google Cloud Storage and has also broadened cloud deals with Microsoft and IBM, aiming to increase cloud...

• ### Evolving data integration strategies target new analytics needs

Most companies don't have a shortage of data, but it's often stored in siloed systems or inconsistent formats -- problems that ...

• ### What goes into a customer analytics data integration framework

Customer data integration is a minefield for IT teams to navigate. But incorporating a set of core technical functions into an ...

## SearchBusinessAnalytics

• ### Data-driven strategy grooms dog care franchise for growth

Camp Bow Wow is growing its day care and boarding business for dogs with the help of a data-driven approach that's powered by a ...

• ### Tableau acquisition of MIT AI startup aims at smarter BI software

Tableau acquires AI startup Empirical Systems in a plan to provide users with automated data modeling capabilities and enable ...

• ### Choosing the right data discovery platform for the enterprise

Obviously, cost and scalability factor into data discovery platform buying decisions, but other features, like visualizations and...

## SearchSAP

• ### Sapphire conference intros raise SAP integration questions

Unveiling of Salesforce challenger C/4HANA and lingering indirect licensing issue give mixed message about SAP's willingness to ...

• ### SAP quietly pulls the plug on SAP Anywhere

Users and analysts say technical limitations and a failure to adequately understand the SMB market contributed to the demise of ...

• ### New tools unveiled to monitor, manage and optimize SAP environments

Vendors announced software to help organizations move to SAP systems, including test automation, code profiling for HANA apps, ...

## SearchSQLServer

• ### Proposed Microsoft-GitHub buy confirms open source role in cloud

The looming Microsoft-GitHub pairing confirms the company's rebirth as an open source friend. Data tools on the Azure cloud are ...

• ### Common Data Service for Analytics eases Power BI integration

Integrating data into Power BI for analysis can be a challenge, but Microsoft's Common Data Service for Analytics technology is ...

• ### Power BI Report Server adds new Power BI reporting options

Updates to Power BI Report Server expand the on-premises platform's reporting functionality and increase the number of data ...

## TheServerSide.com

• ### How to git revert a commit: A simple undo changes example

The best way to undo previous changes to the source code repository is to learn how to git revert a commit.

• ### Jenkins vs. Maven: Compare these build and integration tools

DevOps advocates are often asked for a Jenkins vs. Maven comparison. But those asking often discover that Maven-Jenkins ...

• ### Jenkins environment variables list for shell script build jobs

The Jenkins environment variables list outlines the various properties that developers can inject into advanced Jenkins shell ...

## SearchDataCenter

• ### Why data centers need log management tools

Log files contain rich and useful management data. With the right software tools and a few navigation tips, you can maximize and ...

• ### HPE gives its memory-driven computing initiative another try

HPE has brought its memory-driven computing architecture back into the spotlight, this time with a little help from its friends ...

• ### HPE edge strategy reroutes data, apps around the cloud

HPE's upgraded converged infrastructure systems aim to help enterprises process and manage data outside their data centers and ...

## SearchContentManagement

• ### SharePoint hub sites raises migration questions among users

In the newest rev of SharePoint Online, what used to be sub-sites are now new freestanding sites. This change and others may ...

• ### Cloud DAM platforms vs. on premises for digital asset management

Learn about digital asset management and how cloud DAM democratizes media management and delivery across the enterprise while ...

• ### Box workflow gets upgrade with Progressly purchase

Box is hoping to upgrade its workflow capabilities by adding the startup Progressly to its team, while also still partnering with...

## SearchHRSoftware

• ### News roundup: TriNet software targets professional services

New specialized products include TriNet software for professional services, QuickBooks payroll for contractors and a ...

• ### AI can reduce workplace bias, says CEO of leading HR group

AI technology may help HR reduce workplace bias, according to Johnny Taylor, president and CEO of the Society for Human Resource ...

• ### How to create an effective employee retention plan

The unemployment rate is low, and your workers are likely being courted by other companies. Here's how to create retention ...

Close