Select all records after first meets criteria (1 Viewer)

rgwfly

Registered User.
Local time
Yesterday, 22:57
Joined
Jun 7, 2016
Messages
49
Looking for a query suggestion or SQL where I would pull the first record that contains a certain value and then return all the records after that. I hope this makes sense.
for instance
ID Pass
1 Y
2 F
3 Y
4 Y
5 Y
6 Y
Would return records 2 through 6
or
ID Pass
1 Y
2 Y
3 Y
4 N
5 Y
6 Y
7 N

Would return records 4 through 7
I was thinking a case statement might be a solution but I don't have enough experience to build this.

Thanks for any help you can give.
 

plog

Banishment Pending
Local time
Today, 00:57
Joined
May 11, 2011
Messages
11,638
To achieve what you want, I would use a DMin to retrieve the "First" ID value that contains your value and then use it in the criteria to pull all ID values after that.

Here's some code that demonstrates it using your first example, but probably won't work because I'm just freeballing it:

Code:
SELECT * FROM YourTableNameHere
WHERE ID>=DMin("[ID]", "YourTableNameHere", "[Pass]='F'")
 

rgwfly

Registered User.
Local time
Yesterday, 22:57
Joined
Jun 7, 2016
Messages
49
Plog,
although the above did no pull from the first "F" occurrence; it did pull all the records where there was an occurrence. This is definitely a start. Thank You
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:57
Joined
Feb 28, 2001
Messages
27,140
pull the first record that contains a certain value and then return all the records after that.

Be aware that whatever query you try will have to include an ORDER BY clause. If not, then "all the records after that (record)" has no meaning.

Tables in Access have no intrinsic "natural" order. At best, they might initially appear in the same order they were imported/inserted. But after updates (and possibly a few deletes) it would be impossible to predict table order.

This apparent lack of order happens because Access SQL (and many other versions of SQL) are based on set theory and deal with records as though they were processed simultaneously. OK, we both know that really can't happen that way - but SQL at least ACTS like it happens that way. Witness your observation

it did pull all the records where there was an occurrence

So when you talk about doing something in a particular order, remember that (a) you need an ORDER BY clause and (b) you probably need to work with recordsets in order to see a record at a time because otherwise you are looking at monolithic operation.
 

rgwfly

Registered User.
Local time
Yesterday, 22:57
Joined
Jun 7, 2016
Messages
49
OK Doc that works perfectly Almost.
When I run it with the two elements the order by pulls from the first "R" which is perfect.
Now I would like to add a third element and group them by names.
When I added the third field (Employee) all the records would show up regardless if there was a "R" or not.
My goal is to produce a grouped report from when the first R occurs and every test after so it can be monitored.
 

Users who are viewing this thread

Top Bottom