Fairly new to SQL and databases.... I have the following issue... Database for a shipping company, three relevant tables for this problem are;
Customer (CustomerID, Name, Address etc)
Shipment (ShipmentID, ScheduleName, DepartDate, ArriveDate, DepartPort, ArrivePort)
CustomerOrder (CustomerID, ShipmentID, Fee etc)
I need to show 'All customers that have NOT placed an order within a specific year, i.e. 2019' Im struggling to find the correct query for this. Im working on sample data, there are 8 customers in the database, 3 of which have orders for shipments departing in 2019. Therefore the result im hoping to get is a list of the 5 remaining customers who did not have orders on these shipments.
I can easily show customer who have placed an order and those who have never placed an order however im struggling to show those who haven't placed an order in a specific timeframe.
Any ideas or tips would be greatly appreciated!
Thanks
EDIT***
Desired Result - Show the 5 customers who havent placed an order where the shipping depart date is in 2019
I have tried;
~ SELECT CustomerID from customer LEFT OUTER JOIN customerorder ON Customer.CustomerID = CustomerOrder.CustomerID LEFT OUTER JOIN shipment ON CustomerOrder.ShipmentID = Shipment.ShipmentID WHERE shipment.DepartDate BETWEEN '2019-01-01' AND '2019-12-31' AND CustomerOrder.CustomerID IS NULL ~
However this bring back no results.
The three tables have the following information
Customer - (simply table of customer details) (CustomerID, Name, Address, Tel, Type, Size, RegisteredSince)
Shipment - (Details each shipment scheduled) (ShipmentID, ScheduleName, DepartDate, DepartPort, ArriveDate, ArrivePort, Season)
CustomerOrder - (Details customer order, but not individual items on an order) (OrderID, ShipmentID, CustomerID)
Im not sure if its the join thats the problem? There are 4 shipments in 2019 in the sample data with a total of 3 customers. I need to show the customerID's of the 5 customers who didnt place an order within these dates.
Ive tried a few different queries, have been searching online but im new to this and not quite sure where im going wrong. I am able to identify customers who have never placed an order but as soon as I add the date ranges i get no results.
LEFT JOINis the most common way. - Larnu