Help with SQL for Access - Need to fetch record based on another record

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,801
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I have a table that looks like this:

ClientNo | ClientName | Status | Date

AAA | Andrew | Start | 1/1/17

AAA | Andrew | Round1 | 2/2/17

AAA | Andrew | Done | 3/3/17

AAA | Andrew | Round2 | 4/4/17

AAA | Andrew | Done | 5/5/17

BBB | Bob | Start | 1/2/17

BBB | Bob | Round1| 2/3/17

CCC | Charlie | Start | 5/5/17

CCC | Charlie | Round2| 5/6/17

CCC | Charlie | Done | 7/7/17

DDD |Dawn |Start | 8/8/17

DDD | Dawn |Round1 | 9/9/17

DDD | Dawn | Done | 10/10/17

DDD | Dawn | Round2 | 11/11/17

DDD | Dawn | Done | 12/12/17

DDD | Dawn | Round2 | 12/13/17


What I'm trying to accomplish is to fetch all the ClientNo and ClientNames that has Round2 that has Done after it, as the last couple of actions.

For instance AAA - Andrew and CCC - Charlie would fall into this category but DDD - Dawn would NOT because the last "Round2" is not followed by "Done"

No matter what I tried did not satisfy the need.

Any help is appreciated.

-Iggy
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
get a list that are Done
then join that to those that have a Round2

Code:
select 
  ClientNo, 
  ClientName, 
  Date,  
from 
  my_table 
  inner join 
  (
    select 
      ClientNo, 
      ClientName, 
      Date,  
    from 
      my_table 
    where 
    (
      Status = 'Done'
    ) as tbl 
  )
  on 
  my_table.ClientNo = tbl.ClientNo 
  and 
  my_table.ClientName = tbl.ClientName
where 
(
  Status = 'Round2'
  and 
  my_table.Date <= tbl.Date
)

or do it the other way
get a list that have a Round2 and then join it to those that are Done
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,707
Messages
6,161,416
Members
451,705
Latest member
Priti_190

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