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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:57:07+00:00 2026-05-23T20:57:07+00:00

I have a working query that will return some results(records) from my database, like:

  • 0

I have a working query that will return some results(records) from my database, like:

123|John Williams|IL|M|06/01/2011|ACTIVE
124|Mary Haque|NY|F|TERMINATED|06/30/2011
124|Mary Haque|NY|F|07/01/2011|ACTIVE
125|Alex Chan|VA|07/01/2011|ACTIVE
126|Rob Kreb|VA|TERMINATED|06/20/2011

As you can see, the result is simply a list of customer records, while the last two fields indicate whether the member is active or terminated and associated active/terminated date.

The complication now is, as you can see for member with ID 124 (Mary Haque), she has two records, and for this kind of two-record customer, I only want to keep the row where the member is active while totally ignore her terminated history. So for example, the desired output for the above should be:

123|John Williams|IL|M|06/01/2011|ACTIVE
124|Mary Haque|NY|F|07/01/2011|ACTIVE
125|Alex Chan|VA|07/01/2011|ACTIVE
126|Rob Kreb|VA|TERMINATED|06/20/2011

as you can see, now Mary Haque only has her active information on the result. The above result is generate by a SQL “Select” query, but I couldn’t simply append a “WHERE status=ACTIVE” to this query because I still want to keep the members that only has ONE record like Rob Kreb above even though he is terminated. I only want the filtering for TERMINATED member record to take place when a certain member has two records.

FYI, my current query looks like this:

SELECT * FROM customer_change WHERE CUSTOMER_LOGIN NOT IN(SELECT CUSTOMER_LOGIN FROM  customer_full WHERE CUSTOMER_LOGIN IS NOT NULL)
UNION
SELECT * FROM customer_change WHERE CUSTOMER_POINTS=0 AND CUSTOMER_LOGIN NOT IN(SELECT CUSTOMER_LOGIN FROM customer_full WHERE CUSTOMER_POINTS=0 AND CUSTOMER_LOGIN IS NOT NULL)

Thanks for the help in advance!

  • 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-23T20:57:08+00:00Added an answer on May 23, 2026 at 8:57 pm

    colX and colY are the last 2 columns of the query:

    SELECT *
    FROM (your_UNION_query) AS p
    WHERE NOT ( colX = 'TERMINATED'
              AND EXISTS
                ( SELECT *
                  FROM (your_UNION_query) AS q
                  WHERE q.id = p.id
                    AND q.colY = 'ACTIVE'
                )
              )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Linq to SQL query that was working just fine with SQL
I've been working on optimizing a query and have ran into a situation that's
I have been working with a string[] array in C# that gets returned from
I have been working on some legacy C++ code that uses variable length structures
I have a method that will return a list of suggested orders. If the
I have a mysql query that shows the users last viewed documents. Some sort
I'm writing some code where, most commonly, no results will be returned from a
I am working with database data that manipulates college students exam results. Basically, I
I have SQL query, which is working nice on Oracle and MSSQL. Now I'm
I'm working on returning a recordset from SQL Server 2008 to do some pagination.

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.