Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6729825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:20:10+00:00 2026-05-26T10:20:10+00:00

I am trying to write a query that will return records where the field

  • 0

I am trying to write a query that will return records where the field in column 1 is the same, but there is at least one difference in specific other columns.

For example:
I want to compare columns 2 and 4 for each value in column 1. If there is a difference, I need all fields in both rows to return.

This data set
Column1|Column2|Column3|Column4|Column5
Air Filter|Shape|Round|Color|Red
Air Filter|Shape|Panel
Nerf Bar|Finish|Polished|Material|Stainless Steel
Nerf Bar|Finish|Powder Coated|Material|Stainless Steel
Hood|Color|Black|Finish|Powder Coated
Hood|Finish|Powder Coated|Color|Black

would return:
Air Filter|Shape|Round|Color|Red
Air Filter|Shape|Panel|NULL|NULL
because the value in column 4 does not match between the records
And
Hood|Color|Black|Finish|Powder Coated
Hood|Finish|Powder Coated|Color|Black
because the values in column 2 and column 4 do not match between the records

I can only get one record for each part to return.

Here is the code that I have tried:

Select *
from [My_Table] as a 
where exists(select null from [My_Table] as b
where a.column1 = b.column1
and (a.column2 = b.column2
or a.column3 = b.column3
or a.column4 = b.column4
or a.column5 = b.column5))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:20:10+00:00Added an answer on May 26, 2026 at 10:20 am
    SELECT t1.column1, t1.column2, t1.column3, t1.column4, t1.column5
        FROM My_Table t1
            INNER JOIN My_Table t2
                ON t1.column1 = t2.column1
        WHERE COALESCE(t1.column2,'') <> COALESCE(t2.column2,'')
            OR COALESCE(t1.column4,'') <> COALESCE(t2.column4,'')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a linq query that will only return certain columns
I'm trying to write a HQL/Criteria/Native SQL query that will return all Employees that
I'm trying to write a query that will return data grouped by date ranges
I am trying to write a procedure that will fire the same select query
I'm trying to write a query that will return all QUERY_ID values alongside all
I am trying to write a Facebook query that will return all comments posted
I'm trying to write a query that will return ... Each distinct user id
I'm trying to figure out how to write a MySQL query that will return
I'm currently trying to write a query that will return all users that have
I am trying to write a query that will return only the most recent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.