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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:14:06+00:00 2026-05-26T02:14:06+00:00

Given a resultset like this: Col1 Col2 ============ BAML 491 BARC 362 BDPT 1

  • 0

Given a resultset like this:

Col1    Col2
============
BAML    491
BARC    362
BDPT    1
BNP     9

(select Col1, count(some_col) as Col2 from Table where another_col=’SomeCondition” group by Col1)

and another like this:

Col3    Col2
============
BAML    494
BARC    366
BDPT    1
BNP     10
CALY    3

(select Col3, count(some_col) as Col2 from Table where another_col=’SomeOTHERCondition” group by Col3)

How do I “merge” these two queries to form:

BAML    491       494
BARC    362       366
BDPT    1         1
BNP     9         10
CALY              3

Please note that the first two queries operate on the same table. I can see some variant of Join helping here (haven’t worked with sql all that much). I just can’t figure out how to put those two queries into a single query to get the merged reusltset.

  • 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-26T02:14:07+00:00Added an answer on May 26, 2026 at 2:14 am

    Try this:

    select b.col1, b.col2, a.col2
    from (
        select Col3, count(some_col) as Col2
        from Table
        where another_col = 'SomeOTHERCondition'
        group by Col3
    ) as a
    left outer join (
        select Col1, count(some_col) as Col2
        from Table
        where another_col = 'SomeCondition'
        group by Col1
    ) as b
    on a.col3 = b.col1
    

    I’m not sure if SQLite supports that though.


    Based on the comments the above does work but you really want a FULL OUTER JOIN and SQLite doesn’t like that. You could try faking it with two LEFT OUTER JOINs and a UNION though:

    select b.col1, b.col2, a.col2
    from ... as a left outer join ... as b ...
    UNION
    select b.col1, b.col2, a.col2
    from ... as b left outer join ... as a ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have this resultset structure (superfluous fields have been stripped) Id |
Given a model like this ProductFacets contains the following data: ProductId, FacetTypeId 1, 1
Given this starting CTE: WITH Sections AS ( SELECT 1 Section, 1 StartUnit, 5
I've done a query like this : SELECT Code, kind, SUM(valP) AS value FROM
from a resultset of about 5 different strings, I would like to select the
Given a DBIx::Class resultset, for example: my $rs = $c->model(DB::Card)->search({family_name => Smith}); the tutorials
How to insert the resultset given by the commands RESTORE FILELISTONLY RESTORE HEADERONLY RESTORE
Given a JSON resultset such as the following: [ {fooID: 1, fooLabel: one, barID:
In SQL Server 2005, given the following resultset ID | InstanceNumber | IsArchived 5000
I have a query which returns a result set which looks like this: A

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.