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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:02:47+00:00 2026-06-15T04:02:47+00:00

I am trying to pull records from two tables, a master table, and a

  • 0

I am trying to pull records from two tables, a master table, and a transaction table.

My Master table contains all of my account IDs. My transaction table has any transaction run by these accounts with 3 columns: activity date, income, and charge type.

In the transaction table, some of these accounts may not appear at all because they have not performed a transaction during a given date range. However, I still need these accounts to appear on my result list when I query them.

So my data would look like this:

     Master Table:                         Transaction Table:

    | AccountID  |              | AccountID | ChargeType | ActivityDate| Income |
    --------------              -------------------------------------------------
    |      1     |              |     2     |    2000    |  8/31/2012  | $99.00 |
    |      2     |              |     3     |    2000    |  7/31/2012  | $79.00 |
    |      3     |              |     5     |    2000    |  9/30/2012  | $79.00 |
    |      4     |
    |      5     |

My query currently looks like:

select
    a.AccountID,
    b.ChargeType,
    b.ActivityDate,
    b.Income
From
    MasterTable as A
left join
    TransactionTable as B on a.AccountID = b.AccountID
where
    a.AccountID in ('1','2','3','4','5')
    and
    b.ActivityDate between '5/1/2012' and '11/30/2012'

From what I understand, this query should list all 5 accounts I’ve chosen, and display NULL values for the accounts not found in the TransactionTable.

Results I expect:

        | AccountID | ChargeType | ActivityDate| Income |
        -------------------------------------------------
        |     1     |    NULL    |     NULL    |  NULL  |
        |     2     |    2000    |  8/31/2012  | $99.00 |
        |     3     |    2000    |  7/31/2012  | $79.00 |
        |     4     |    NULL    |     NULL    |  NULL  | 
        |     5     |    2000    |  9/30/2012  | $79.00 |

The incorrect results I receive instead:

         | AccountID | ChargeType | ActivityDate| Income |
         -------------------------------------------------
         |     2     |    2000    |  8/31/2012  | $99.00 |
         |     3     |    2000    |  7/31/2012  | $79.00 |
         |     5     |    2000    |  9/30/2012  | $79.00 |

I assume I am misunderstanding something fundamental here. Any help is greatly appreciated!

Thanks in advance!

  • 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-15T04:02:49+00:00Added an answer on June 15, 2026 at 4:02 am

    The reason is that you have the “b” table referenced in the where clause, so NULL values are filtered out.

    Move the condition to the on clause:

    From
        MasterTable A left join
        TransactionTable B
        on a.AccountID=b.AccountID and
           a.AccountID in ('1','2','3','4','5') and
           b.ActivityDate between '5/1/2012' and '11/30/2012'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I am just trying to pull all the records from my database
I am trying to pull a specific set of records from a table called
I am trying to create several models that all pull from the same table.
Basically, I'm trying to pull the records from a table with a many-to-many relationship
I am trying to pull some records from a table (BidNames) and pass them
Just trying to pull off some SMART info from connected Hard Drives on any
I'm trying to pull data from the YouTube API into a local MySQL table.
I have two tables from which I'm trying to run a query to return
So I have three tables I am trying to pull data from with the
I have two tables (country & ducks) where the country table has every country

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.