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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:09:51+00:00 2026-05-25T16:09:51+00:00

I have two tables: one for transacctions and one for bills. It could be

  • 0

I have two tables: one for transacctions and one for bills. It could be aprpoved transactions that generates a bill. There could be NOT approved transactions that NOT generates a bill.

The problem is that I would like to print the info of both tables, but is not possible to see if there will be (or not) a bill.

Some representatives fields are from:

Transactions:  service_bill, auth_number, UserId ...
Bill: UserId, ...

When I do the query:

    SELECT *
    FROM transactions, bill
    WHERE MONTH(date) = '09'
    AND 
    YEAR(date) = 2011
        (...)
        AND
        bill.userId = transactions.userId
        (...)
    ORDER BY id_transaction

If I use that query, I will print the information that matchs the “userId”, but the problem is that it WONT print the transactions that does not have bills -because, you don´t have an userId to match-

If I relax the where, it will print several times the same information :/

At the end, I want to print all the information -without repetitions- and in the NOT generated bills, when the transactions is displayed the bill info is NULL or something like that.

Any idea to solve 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-05-25T16:09:52+00:00Added an answer on May 25, 2026 at 4:09 pm

    You want to use a LEFT JOIN in this case. This returns all rows from the first table along with any matches found in the second table. Any unmatched rows will return NULL values for the columns of the second table.

    SELECT *
        FROM transactions t
            LEFT JOIN bill b
                ON t.userId = b.userId
        WHERE MONTH(date) = '09'
            AND YEAR(date) = 2011
        (...)
        ORDER BY t.id_transaction
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, one that contains volunteers, and one that contains venues. Volunteers
Lets say I have two tables, one for transactions, and another table who's primary
I have two tables: one contains employees information and another is transactions (sales) information
I have a deadlock problem with two transactions that do not access any common
I have two tables one has a three column composite key. The other needs
I have two tables, one stores the products and quantity we have bought, the
I have two tables, one for routes and one for airports. Routes contains just
I have two tables, one called cart and one called items. Now I want
I have two tables. One (Widgets) has a list of widgets (ID, widget_name, color,
I have two tables, one Company and one Employee: class Company(models.Model): name = models.CharField(max_length=60)

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.