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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:13:29+00:00 2026-05-26T12:13:29+00:00

Is there any advanced Oracle SQL methods to solve this kind of situation? Simplified:

  • 0

Is there any advanced Oracle SQL methods to solve this kind of situation?

Simplified:
Two queries returns primary_key_value and other_value.
Both queries always return primary_key_value but other_value might be null.

So how I can union those two queries so that it returns always those rows which has other_value, but if both queries are having other_value = null with same primary key, then only one row should be returned.

I know this is so stupid case. But specifications were like this 🙂

Example:
First query:

A  |  B
=======
1  | X
2  | 
3  | 
4  | Z

Second query:

A  |  B
=======
1  | Y
2  | 
3  | Z
4  | 

So result need to be like this:

A  |  B
=======
1  | X
1  | Y
2  | 
3  | Z
4  | Z
  • 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-26T12:13:30+00:00Added an answer on May 26, 2026 at 12:13 pm

    You could use analytics:

    SQL> WITH q1 AS (
      2     SELECT 1 a, 'X' b FROM DUAL UNION ALL
      3     SELECT 2 a, ''  b FROM DUAL UNION ALL
      4     SELECT 3 a, ''  b FROM DUAL UNION ALL
      5     SELECT 4 a, 'Z' b FROM DUAL
      6  ), q2 AS (
      7     SELECT 1 a, 'Y' b FROM DUAL UNION ALL
      8     SELECT 2 a, ''  b FROM DUAL UNION ALL
      9     SELECT 3 a, 'Z' b FROM DUAL UNION ALL
     10     SELECT 4 a, ''  b FROM DUAL
     11  )
     12  SELECT a, b
     13    FROM (SELECT a, b,
     14                 rank() over(PARTITION BY a 
     15                             ORDER BY decode(b, NULL, 2, 1)) rnk
     16             FROM (SELECT * FROM q1
     17                    UNION
     18                   SELECT * FROM q2))
     19   WHERE rnk = 1;
    
             A B
    ---------- -
             1 X
             1 Y
             2 
             3 Z
             4 Z
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any favorite online references or good introductory and intermediate/advanced books on this
Is there any sql*plus command to remove \r \n and \t from the result
I have a rather weak understanding of any of oracle's more advanced functionality but
Is there any equivalent of the VS7/8/9/10 Edit -> Advanced -> Format Document (
I'd like to know if there are any good EF providers for Oracle out
I am developing a small web app. There isn't any advanced functionality, just basic
Is there any reason why I couldn't include two mysql_fetch_array statements working on two
Was just wondering if there were any good free advanced asp.net grid controls that
Q: Is there any way to implement self-documenting enumerations in standard SQL? EXAMPLE: Column:
In Oracle, there's a view called V$SQLAREA that lists statistics on shared SQL area

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.