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

  • Home
  • SEARCH
  • 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 256269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:00:00+00:00 2026-05-11T22:00:00+00:00

For an access database that looks like this: (All text fields) Co1 Co2 Co3

  • 0

For an access database that looks like this:
(All text fields)

Co1 Co2 Co3 Co4
A   k   t   N1
B   k   t   N2
A   m   t   N3
B   k   z   N4
A   k   z   N5
C   m   t   N6
C   k   z   N7
C   k   t   N8
A   k   t   N9
C   m   t   N10

I need to create some kind of reports that would do the following:

The results needs to select rows:

  1. Ordered by Co1 first
  2. then ordered by Co2
  3. only include data where Co3 = t or r
  4. when Co3 is NOT t nor r, then all other rows with a prior C04 where
    Co1 AND Co2 were the same as the current row are also excluded

1,2 and 3 are extremely easy to do (Order by and Where clause respectively) but
can #4 be done in access SQL?
If it can’t, I’ll make a small C# app that loops through the data but I feel this
must be possible to do in SQL and if it can that would definately be much better.

The actual query and database is more complicated but #4 is where I get stuck.

With the example I gave the result would be:

A   m   t   N3
A   k   t   N9
C   m   t   N6
C   m   t   N10
C   k   t   N8

I believe this cover all possible cases.

Precision, we use the fourth column (C4 in this example) to determine the order
but it is a text field with characters and digits in it.
The field is a letter followed by 2 digits: A01, A02,..A99, B01, etc…
Precision #2, I’m not the one to blame for this database design. 😛

So, to the SQL guru’s among us, can this be done in access SQL? How?

Thank you very much for any help you can provide.

  • 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-11T22:00:00+00:00Added an answer on May 11, 2026 at 10:00 pm

    If I read you correctly:

    when Co3 is NOT t nor r, then all
    other rows with a prior C04 where Co1
    AND Co2 were the same as the current
    row are also excluded

    That is equivalent to excluding rows for which a later row with certain conditions exist. You can do that with a NOT EXISTS clause:

    select *
    from YourTable cur
    where cur.Co3 in ('t','r')
    and not exists (
        select *
        from YourTable later
        where cur.Co1 = later.Co1 
        and cur.Co2 = later.Co2
        and later.Co3 not in ('t','r') 
        and CInt(Mid(later.Co4,2)) > CInt(Mid(cur.Co4,2))
    )
    order by cur.Co1, cur.Co2 desc, CInt(Mid(cur.Co4,2))
    

    Now N10 is not bigger than N5 normally. That’s what the CInt(Mid(…,2)) is for: it turns N10 into the number 10, and the number N5 into 5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 206k
  • Answers 206k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My Boss found the answer: It appears that the “<property>”… May 12, 2026 at 9:11 pm
  • Editorial Team
    Editorial Team added an answer I viewed source on your page and it looks like… May 12, 2026 at 9:11 pm
  • Editorial Team
    Editorial Team added an answer Using manpages For basic C functions, the manpages should work.… May 12, 2026 at 9:11 pm

Related Questions

It's nothing new to de-couple the data access code from your business objects, but
I've just found out about Stack Overflow and I'm just checking if there are
I'm a little stumped on this one. Anyone have any ideas? I'll try to
I am stuck figuring out a working SQL Query for the fallowing: I need

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.