Solved

SQL Syntax: LEFT OUTER JOIN (Group By Table)

Posted on 2009-04-13
4
469 Views
Last Modified: 2012-05-06
Given: an events table and a clients_payments_received_table, using Access 2003

I would like to Left (outer) JOIN events to the following result

SELECT clients_payments_received.clpr_eventid, SUM(clients_payments_received.clpr_amount) AS total_payments
FROM clients_payments_received
GROUP BY  clients_payments_received.clpr_eventid

Would like to do this in one SQL statement.

Any ideas?
0
Comment
Question by:djlurch
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24133716
you might try this:
SELECT cp.clpr_eventid, SUM(cp.clpr_amount) AS total_payments , e.event_name
FROM clients_payments_received cp
LEFT OUTER JOIN events e
  ON ( e.eventid = cp.clpr_eventid )
GROUP BY  cp.clpr_eventid, e.event_name

Open in new window

0
 
LVL 1

Author Comment

by:djlurch
ID: 24133927
Uggg. Not what I was looking for. (My Fault) The query works...but it doesn't return the results that I want.

I am looking for all results from the events table with a ZERO value for events that don't have any payments.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24133968
no problem, just reverse the join:
SELECT e.eventid, e.event_name, SUM(cp.clpr_amount) AS total_payments 
FROM events e
LEFT OUTER JOIN clients_payments_received cp 
  ON ( e.eventid = cp.clpr_eventid )
GROUP BY e.eventid, e.event_name

Open in new window

0
 
LVL 1

Author Closing Comment

by:djlurch
ID: 31569715
You rock. Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL trigger 5 21
SQL Syntax Grouping Sum question 7 24
Comparison query - 4 columns 9 23
SQL Recursion schedule 13 14
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question