473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Please help me in choosing an SQL statement (inner, outer or left join)

222 100+
Dear Sirs;


I'm trying to write SQL statement and it is not executing what I need.

tables are: customers(customerID, customerName)
Invoices(invoiceID,customerid,invoicedate,invoicea mount)
Receipt (receiptID,customerid,receiptdate,receiptamount)

using inner outer an left join is always making a combination on the query.

what i need is just to add to queries to each other for example:

invoiceID customerID invoicedate receiptamount receiptdate receiptID

22--------------171-----------1/1/2006-------------- 0 --------------0 -------------- 0
0----------------171--------------0-------------- -----120-----------1/2/2006---------21
0----------------171--------------0--------------------360-----------1/3/2006---------22
23---------------171----------1/4/2006--------------0 --------------- 0 ----------------0

The idea is to sort this query by date.

My relationship is connected table customers by invoices and customers by receipt (1 to infinity customerid to customerid(invoices and receipt))

I don't want any duplication in data.

does my relationship map me to this kind of query ?
Is there any feature that report in Access provide to such as queries?

Any help guys please please I read this articles many times
http://bytes.com/forum/thread608296.html and i don't think a single sql statement will help me

I WOULD BE MORE THAN HAPPY TO HEAR FROM YOU.




WASSIM S DACCACHE
Apr 27 '08 #1
5 1440
Delerna
1,134 Expert 1GB
try making a query for each of the tables.Each query will that take the fields that are in its table and adds fields that are not in its table. So each table will have that same fields that are in your result.

Then you can use a union query to join the results of the three queries into 1 recordset and sort them by date.

I can provide an example if you have trouble doing that.
Apr 27 '08 #2
wassimdaccache
222 100+
Man;


Still have duplication in values.

Kindly, provide me more details or example.

Appreciate your help


WASSIM S DACCACHE
CCE
Apr 28 '08 #3
Delerna
1,134 Expert 1GB
actually you only need the two tables

Expand|Select|Wrap|Line Numbers
  1.  
  2. select invoiceID,
  3.         customerID,
  4.         invoicedate,
  5.         InvoiceAmount as Amount,
  6.         0 as receiptdate,
  7.         0 as receiptID
  8. from Invoices
  9. union all
  10. select 0 as invoiceID,
  11.         customerID,
  12.         0 as invoicedate,
  13.         receiptamount as Amount,
  14.         receiptdate,
  15.         receiptID
  16. from Receipt
  17.  
By the way
The reason you are getting duplicates with the joins is that there are 2 invoices and 2 receipts for a single customer which are probly for two seperate orders.
You have nothing to distinguish the two invoices from one another in your join, such as an order number. Ditto for the invoices.
so when you join the invoices to the receipts.
For each invoice there are 2 matching receipts, therefore the 2 invoices return 4 records.
I hope that I explained that clearly enough.
Apr 28 '08 #4
wassimdaccache
222 100+
Dear Delerna,



I understood your logic. I appreciate you it works with me.


Thank you again for all your feedback and your aid.


Best regards;



WASSIM S DACCACHE
CCE
<< Link removed in Technical Thread >>
Apr 29 '08 #5
NeoPa
32,556 Expert Mod 16PB
Wassim,

FYI The rules prohibit inclusion of links in the technical posts (except where they're part of the question).

I've removed the link and I'm sure it was done in innocense so no real problem.
Apr 30 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Stephen Patten | last post by:
Hi All, While in the process of building my table (40 or so Insert statments) can I then query ("select * from @Table_variable") and use the results up to theat point for another insert into...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
8
by: kieran | last post by:
Hi, I have the following sql statement. I originally had the statement with two INNER JOINS but in some situations was getting an error so changed the last INNER JOIN to a LEFT OUTER JOIN (as...
1
by: brett | last post by:
Here is my SQL string: "SELECT to_ordnum, to_orddate," _ & "(SELECT SUM((DDPROD.pr_stanmat * DDPROD.pr_prfact) * (DOBOM2.b2_quant * DDORD.or_quant)) FROM DDPROD INNER JOIN DOBOM2 ON...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
1
by: Bob Alston | last post by:
I am trying to use an access sql statement in a module that does a left outer join on one table - joined to a table that has a selection criteria. The result is an inner join. If I do this in...
15
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
8
by: gimme_this_gimme_that | last post by:
I want to execute the following SQL statement for a single emp.emp_id. Just adding and emp.emp_id=256 to the end of the statement results in a SQL statement that on average takes 5.5 seconds. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.