Show Duplicates Across 2 Queries

QandAdam

New Member
Joined
Jan 12, 2019
Messages
30
I have 2 queries:

Both Queries have the same fields and are based on the same table (tblBusinesses) but have different criteria

Query NameCriteria
OpenBusinesses'Status' field equals 'Open'
ClosedBusinesses'Status' field is not equal to 'Open'

<tbody>
</tbody>

Is there a way to find records which appear in both queries? The Duplicate field will be the 'RegNo' within the table.

Basically, I'm trying to find any Duplicate Businesses Records which have different Statuses. If there is a better way of doing this then I'm all ears!

Thanks in advance!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Remove status field, group on RegNo and add a count with criteria > 1 ?

HTH
 
Upvote 0
Remove status field, group on RegNo and add a count with criteria > 1 ?

HTH

How would this filter to only show the duplicate RegNos with different statuses?

E.g.
Instead of this:
RegNoStatus
123Active
123Closed
456Closed
456Closed

<tbody>
</tbody>

I want it to look like this:
RegNoStatus
123Active
123Closed

<tbody>
</tbody>

RegNo '456' is ignored because although it is a duplicate RegNo, the Status on both records is 'Closed'
 
Last edited:
Upvote 0
Distinct, then count ...
Code:
select count(RegNo) as Total
from
(
select distinct RegNo, Status
from [Businesses]
) T
having count(T.RegNo) > 1


Another way (not necessarily distinct if there are even three or more records, some open others closed):
Code:
select t1.RegNo from [Businesses] t1 
where 
    t1.Status = 'Open' 
and exists (select * from [Businesses] t2 where t2.RegNo = t1.RegNo and t2.Status = 'Closed')
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top