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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:01:44+00:00 2026-06-13T05:01:44+00:00

I have 2 queries like : select id, count(something) selected from table1…; select id,

  • 0

I have 2 queries like :

select id, count(something) selected from table1...;
select id, count(something) rejected from table2...;

The first query gives me

id selected
------------
2  4
3  5

The second query gives me

id rejected
------------
1  12
3  13

I wish to combine them into the following form through a single query

id selected rejected
--------------------
1  null      12
2  4         null 
3  5         13

How can I achieve 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-13T05:01:45+00:00Added an answer on June 13, 2026 at 5:01 am

    You need to simulate SQL Server‘s FULL OUTER JOIN by combining the UNIONed results of LEFT and RIGHT joins (but in my case both are LEFT JOIN as I used to to this)

    SELECT  a.ID, a.selected, b.rejected
    FROM    (selectedQuery) a
            LEFT JOIN (rejectedQuery) b
                ON a.ID = b.ID
    UNION 
    SELECT  a.ID, b.selected, a.rejected 
    FROM    (rejectedQuery) a
            LEFT JOIN (selectedQuery) b
                ON a.ID = b.ID
    

    SQLFiddle Demo

    UPDATE 1

    PostgreSQL Supports FULL OUTER JOIN (my bad)

    SELECT  COALESCE(a.ID,b.id) ID, a.selected, b.rejected
    FROM    selectedQuery a
            FULL OUTER JOIN rejectedQuery b
                ON a.ID = b.ID
    

    SQLFiddle Demo

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

Sidebar

Related Questions

I have to join queries from multiple databases, something like: SELECT T1.*, T2.* FROM
I have 2 tables, using an inner join to query them. SELECT COUNT(table2.id) FROM
I have a lot of SQL queries like this: SELECT o.Id, o.attrib1, o.attrib2 FROM
I have two mysql queries: $sql = SELECT * FROM content WHERE threadName LIKE
i have a query that goes like this: $get_feed_amount = mysql_query( SELECT COUNT(*) as
I have two queries with subqueries for dateparts which I like to join. SELECT
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have two queries that I run in the same table: SELECT id, COUNT(up)
I have a fairly complex query that looks something like this: create table Items(SomeOtherTableID
I'am using GWT 2.4 with Hibernate and RequestFactory and I have queries like this

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.