Hi Guys,
Really need some help with this one.
So lets say I have a customer table, orders table, and a quotes table. Customers and orders have a one-to-many relationship. So does Customers and Quotes.
Customer 1 -----> Many Orders
Customer 1 -----> Many Quotes
How would I create a view that would return a list of all customers with only one Quote ID whith the earliest QuoteDate and only one Order ID with the latest OrderDate?
eg. Result should look something like this:
Customer Table:
ID Name
1 Test Co
2 Test Pty
3 Testing Co
Result Should Look Like:
CustomerID CustomerName QuoteID Quote Date OrderID OrderDate
1 Test Co 34 2017-10-01 55 2017-10-23
2 Test Pty 24 2017-10-02 57 2017-10-29
3 Testing Co 39 2017-10-01 65 2017-10-27
Thus, all customers should be returned in the view, regardless of the existence of either a quote or order, but if they exist return the earliest quote and the latest order or replace values with null if either does not exist.
Aprreciate any help
Really need some help with this one.
So lets say I have a customer table, orders table, and a quotes table. Customers and orders have a one-to-many relationship. So does Customers and Quotes.
Customer 1 -----> Many Orders
Customer 1 -----> Many Quotes
How would I create a view that would return a list of all customers with only one Quote ID whith the earliest QuoteDate and only one Order ID with the latest OrderDate?
eg. Result should look something like this:
Customer Table:
ID Name
1 Test Co
2 Test Pty
3 Testing Co
Result Should Look Like:
CustomerID CustomerName QuoteID Quote Date OrderID OrderDate
1 Test Co 34 2017-10-01 55 2017-10-23
2 Test Pty 24 2017-10-02 57 2017-10-29
3 Testing Co 39 2017-10-01 65 2017-10-27
Thus, all customers should be returned in the view, regardless of the existence of either a quote or order, but if they exist return the earliest quote and the latest order or replace values with null if either does not exist.
Aprreciate any help