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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:51:02+00:00 2026-06-07T21:51:02+00:00

sorry for the poorly titled post. Say I have the following table: C1 |

  • 0

sorry for the poorly titled post.

Say I have the following table:

C1 | C2       | c3
1  | foo      | x
2  | bar      | y
2  | blaz     | z
3  | something| y
3  | hello    | z
3  | doctor   | x
4  | name     | y
5  | continue | x
5  | yesterday| z
6  | tomorrow | y

I’m trying to come up w/ a sql statement which performs the following union:
1st retrieval retrieves all records w/ c3 = ‘y’

2nd retrieval retrieves the first instance of a record where c3 <> ‘y’ and the result is not in the previous union

So, for the result, I should see:

C1 | C2   
1  | foo  
2  | bar 
3  | something
4  | name
5  | continue
6  | tomorrow    

So two questions: 1: Am I totally smoking crack where I think I can do this, and 2: (assuming I can), how do I do this?

  • 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-06-07T21:51:04+00:00Added an answer on June 7, 2026 at 9:51 pm

    Try this one:

    SELECT   a.C1, a.C2
      FROM   MyTable a
     WHERE   a.C3 = 'y'
        UNION
    SELECT   b.C1, b.C2
      FROM   MyTable b
     WHERE   b.C3 <> 'y' AND
             b.C1 not in 
                (
                   SELECT c.C1
                     FROM MyTable c
                    WHERE c.C3 = 'y'
                )
    

    UPDATE 1

    by the way, why is that there is only one record of 5 in your desired result? where, in fact, there could be two.

    SEE FOR DEMO 1

    OR

    SELECT g.C1, MIN(g.C2) C2
    FROM
    (SELECT   a.C1, a.C2
      FROM   MyTable a
     WHERE   a.C3 = 'y'
        UNION
    SELECT   b.C1, b.C2
      FROM   MyTable b
     WHERE   b.C3 <> 'y' AND
             b.C1 not in 
                (
                   SELECT c.C1
                     FROM MyTable c
                    WHERE c.C3 = 'y'
                )
    ) g
    GROUP BY g.C1 
    

    SEE FOR DEMO 2 (yields same result with your desired result)

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

Sidebar

Related Questions

Sorry to ask something that others have already asked. But when I use the
I am sorry if I am asking the question poorly. I have a Rails
Sorry, poorly descripted title and couldn't think of how to phrase it. Working on
Sorry I am very new to open graph and have been having difficulty to
Sorry I have a problem with with the fancy left apostrophe showing up in
Sorry about the poorly articulated title, I couldn't think of a title that would
Sorry for the poorly-worded question. I was hoping to get everyone's ideas on the
First I'm pretty new to Javascript, so sorry if my question comes across poorly.
I was wondering what the best approach would be to the following problem. Say
Sorry, My English is not good, I have a View: <div class=editor-field id =

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.