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.

#### 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

• ### Open source database use is a growing trend

Study shows that more users are using open source software for data management, with most organizations using more than one ...

• ### Databricks contributes Delta Lake to the Linux Foundation

Databricks has found a new home at the Linux Foundation for its open source Delta Lake data lake project, in a bid to help grow a...

• ### Apache Rya matures open source triple store database

Open source triple store database technology used by the U.S. Navy moves forward as a stable, mature project at the Apache ...

## SearchBusinessAnalytics

• ### New tools add AI power to Teradata Vantage platform

Teradata unveiled Vantage Analyst and Customer experience, two new tools now part of the vendor's analytics platform, on Tuesday ...

• ### SAS analytics platform aided by \$1 billion AI investment

The SAS suite of business intelligence products is quickly seeing results from the vendor's \$1 billion commitment to AI seven ...

• ### ThoughtSpot BI platform an early adopter of AI

Due to AI, ThoughtSpot's analytics tools have been accessible to citizen data scientists from the start, Andrew Yeung, the ...

## SearchSAP

• ### Road ahead for new SAP leadership team isn't an easy one

New SAP co-CEOs Jennifer Morgan and Christian Klein must clarify SAP's products strategy, explain the experience economy and help...

• ### CEO of SAP Bill McDermott abruptly resigns

Bill McDermott, CEO of longtime ERP, CRM and BI software vendor SAP, resigned Thursday triggering a succession plan that promotes...

• ### What is an SAP Intelligent Enterprise? Don't look for a clear answer

What does Intelligent Enterprise actually mean? If the SAP term confuses you, you're not alone. Learn what the experts say and ...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Is Java slow? Compared to C++, it's faster than you think

If you find that Java is slower than other languages, such as C++, here's how to better compare the two and the major differences...

• ### Java video games, like Minecraft, keep the language popular

The next generation of Java developers can learn the ins and outs of the language through an unlikely source: video games such as...

• ### Pivotal, Microsoft team up to deliver Azure Spring Cloud

Azure Spring Cloud, jointly developed by Microsoft and Pivotal, lets Spring developers bring apps to the cloud without concern ...

## SearchDataCenter

• ### Improve server rack physical security with ISO standards

Safeguarding information access is essential to data center operations. With ISO Standard 27001 and the right locking mechanisms,...

• ### Essential private cloud migration steps

Executive buy-in, application evaluation and tool configuration are all important parts of cloud selection. With these steps, ...

• ### IBM quantum computers' usefulness in sight -- using binoculars

IBM's Bob Sutor discusses Big Blue's new quantum systems and computation center, the realities of quantum computing today and how...

## SearchContentManagement

• ### Alfresco Software acquires SAP connector company Pernexas

The acquisition aims to make gaining new customers easier by providing another option to SAP customers looking for a cloud-native...

• ### 5 tips to avoid content sprawl when using Microsoft Teams

Businesses should heed this advice when rolling out Microsoft Teams to avoid content sprawl and ensure users can easily find the ...

• ### WebPurify launches profanity filter for memes and images

WebPurify has launched a beta of its Optical Character Recognition Profanity Filter Service to identify and block profane images ...

## SearchHRSoftware

• ### A backlash emerges over automated interviewing

Illinois may have adopted the nation's first automated hiring law, which will take effect Jan 1. The law is likely to become a ...

• ### Get smarter about HR data security

HR deals with mountains of sensitive employee data and must do a better job of protecting that information. Here's a look at how ...

• ### Walmart, FedEx make case for VR training

The payback from virtual training may be improved retention and shorter training times. An hour-long training period can be ...

Close