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 8190021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:28:50+00:00 2026-06-07T03:28:50+00:00

I have a table, horribly designed (not my doing thankfully), that stores data in

  • 0

I have a table, horribly designed (not my doing thankfully), that stores data in a fashion similar to the following:

[key], [lease_id], [building_name], ~20 more columns of data

A lease_id can and will exist for a centre as well as head office. I’ve been asked to find all instances where data in a building for a lease doesn’t match data in head office for the same lease.

I can do this, quite easily, with a self join. The challenge here is that there are about 20 columns to compare and although I could type each one in manually I was wondering if there’s a better way to do this (which would also mean the query can be used in future, accounting for any table changes).

In syntaxtically ridiculous psuedo code- I want to do something similar to what the following would do if it were to work:

select  lp.*
from    lease_proposal lp
        inner join
        (
            select  *
            from    lease_proposal lp2
            where   building_id = '001' -- assume 001 is head office for sake of example
        ) lp2
            on lp2.lease_id = lp.lease_id
where   lp.* <> lp2.*
  • 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-06-07T03:28:51+00:00Added an answer on June 7, 2026 at 3:28 am

    You could do an INTERSECT operation to find all rows where all data matched, then LEFT JOIN that result and select only the rows where there wasn’t an intersection:

    SELECT
        a.*
    FROM
        lease_proposal a
    LEFT JOIN
        (
            SELECT *
            FROM lease_proposal
    
            INTERSECT
    
            SELECT *
            FROM lease_proposal
            WHERE building_id = 001
        ) b ON a.lease_id = b.lease_id
    WHERE
        b.lease_id IS NULL
    

    If SQL Server supported it, you could also use a NATURAL LEFT JOIN like so:

    SELECT  
        a.*
    FROM
        lease_proposal a
    NATURAL LEFT JOIN
        (
            SELECT *
            FROM lease_proposal
            WHERE building_id = 001
        ) b
    WHERE b.lease_id IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table of data that is sorted as follows: Item | Sample |
I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10
Let's say I have the following data in the Customers table: (nothing more) ID
I have a table with the following column: NOTEID NUMBER NOT NULL, For all
I have table with around 70 000 rows. There is 6000 rows that i
I have 3 values that I need to copy from one table to another
Basically, I'm dealing with a horribly set up table that I'd love to rebuild,
I have a table I need to perform a horrible query on (not my
I have a table that looks like id, parentId, name 1, null, first 2,
Just looking for opinions on the following 2 scenarios. We have a table where

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.