0

I have a query like this:

Select * from
  (Select a, b, c from table1 where some condition) as Result1,
  (Select d, e from table2 where some another condition) as Result2 

everything is OK until one of the nested selects returns nothing, then another select returns nothing too in finally select.

please tell me what is wrong with me?

6
  • replace your select statement with coalesce or is null function that will prevent you from throwing null value error Commented Sep 25, 2017 at 7:31
  • 1
    Please Edit your question and add some sample data and the expected output based on that data. Formatted text please, no screen shots. edit your question - do not post code or additional information in comments. Commented Sep 25, 2017 at 7:35
  • @AnkitAgrawal thanks for your comment, possible give me a sample, i'm new in posgresql, i did this with join in mysql Commented Sep 25, 2017 at 7:35
  • Use a full outer join between your two resultsets, rather than a Cartesian product. Commented Sep 25, 2017 at 7:35
  • @Phylogenesis i did this but it doesn't work first because i didn't know that ON condition join in postgresql is forced. finally it's working with this: Select * from (Select a, b, c from table1 where some condition) as Result1 FULL OUTER JOIN (Select d, e from table2 where some another condition) as Result2 ON 1 = 1 Commented Sep 25, 2017 at 7:44

2 Answers 2

1

As per my comment above, the following should work how you expect:

select
    *
from
    (select a, b, c from table1 where predicate1) Result1
full outer join
    (select d, e from table2 where predicate2) Result2 on
        1 = 1
Sign up to request clarification or add additional context in comments.

1 Comment

that's exactly i did! Thanks
0
  1. Try:

    Select (
      (Select a, b, c from table1 where some condition) as Result1,
      (Select d, e from table2 where some another condition) as Result
    )
    
  2. Try an inner or self join

  3. Post some result samples to get a better understanding of the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.