Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

SQL Query Relationship

User generated imageplease take a look of the attached file. It is a simple invoice to receipt (1 to m) relationship. and my question is.

1. assume I give you receipt received to date range 01/01/2019 to 01/14/2019. how can get the following in SQL query.

Invoice ID Total Receipt Count Receipt Amount
1                 25.00              1
2                 0                      0
3                 0                      0
ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITsolutionWizard

ASKER

I expect to get one invoice per line. meaning no duplication of invoice should be occurred in the list result.
Yes, above query will give one invoice per line..
what is left and right join means...
Sorry, if you are very new to SQL JOINS, then I would suggest you to go through this wonderful article(series) about JOIN so that you would know about JOINs completely..
In simple words, LEFT JOIN will bring all records from LEFT tables and non matching records in RIGHT table will have NULL values.
RIGHT JOIN will bring all records from RIGHT table and non matching records in LEFT table will have NULL values.
https://sqlity.net/en/1146/a-join-a-day-introduction/
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

If you like Venn Diagrams and pictures, this is one of the best I've seen at explaining joins:
https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins