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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:36:26+00:00 2026-06-05T03:36:26+00:00

I have two tables which I am left joining together. SELECT Col3, tab1.Col1, tab1.Col2

  • 0

I have two tables which I am left joining together.

SELECT Col3, tab1.Col1, tab1.Col2 FROM
    (SELECT Col1,Col2 
    FROM Table1
    GROUP BY Col1,Col2) tab1
LEFT JOIN
    (SELECT Col3, Col1, Col2
    FROM Table2
    GROUP BY Col3, Col1, Col2) tab2
ON tab2.Col2 = tab1.Col2 AND tab2.Col1 = tab1.Col1

At the moment for the rows in Table1 which do not exist in Table2 I return a row where Col3 is Null. As I am grouping data based on Col3, it would be good if I could somehow get the value of Col3 instead of Null…..

Is this possible??

So I am trying to return every possible combination of col1 and col2, per value of col3. The problem is when col3 does not contain a particular combination of col1,col2 I am getting nulls for col3…

  • 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-05T03:36:28+00:00Added an answer on June 5, 2026 at 3:36 am

    Assuming Col3 is some kind of category, and is a primary key of a category table, you might do this:

    select Category.Col3,
           tab1.Col1,
           tab1.Col2,
           sum (tab2.YourAggregate) SumOfSomething
     -- Take all categories
      from Category
     -- Cartesian product with Tabl1
     cross join Table1 tab1
     -- Find matching records in Table2, if they exist
      left join Table2 tab2
        on Category.Col3 = Tab2.Col3
       and Tab1.Col1 = Tab2.Col1
       and Tab1.Col2 = Tab2.Col2
     group by Category.Col3,
           tab1.Col1,
           tab1.Col2
    

    Cross join produces Cartesian product of tables involved, retrieving Col3 which might not be found in Table2.

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

Sidebar

Related Questions

I have two tables which I want to join together using a left outer
I have two tables that I am outer joining together: Post left outer join
I have two tables as below: Student: oneID (primary key), col1, col2, col3, subId,
I have two different tables from which I need to pull data blogs which
When LEFT JOINing two tables, is there a way to set the cells which
i have two mysql tables which are linked together and i need to show
I have two tables which looks something like this Table Queue int ID; string
I have two tables which are used to store details of different types of
I have two tables which have some transactional stuff stored in them. There will
I use Hibernate with Java. I have two tables which are associated with foreign

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.