I am designing a database for a publishing house to track magazine shipping and also to keep a history of it.
I have three tables (simplified):
Subscriber id (pk) subscribers_number (unique) first_name last_name shipping_address last_payment Shipping id (pk) date issue ShippingAddress id (pk) shipping_id (fk) subscriber_id (fk) subscribers_number first_name last_name shipping_address NonDeliveryReport id (pk) shipping_address_id (fk) reason resolved
Subscriber is a list of people who pay to receive a monthly issue of their magazine. Not every subscriber is eligible to receive the next issue. To make it simple, a subscriber receives the next issue only if
last_payment date is withing the last 60 days. There are some more conditions, but I’ll get into that later.
When the next issue is ready to be shipped, a
Shipping is created.
Then we select all eligible
Subscribers and create a
ShippingAddress for each one and copy the value of
shipping_address from the
Subscriber to the new
ShippingAddress. We do this so that we have an unmutable history of shipments, even if a
Subscriber changes his/her address, or is deleted from the database. For ease of use, there is a nullable foreign key
subscriber_id in addition to the hard copy of the
If the mail company could not deliver to a subsriber’s
ShippingAddress, they return a non-delivery report to us. For each report, a
NonDeliveryReport is created and references the affected
Now we are getting to the important part of my question:
When we create a Shipping, we have to select all
Subscribers, that are eligible. Eligible is every subscriber, except for anyone, who has a non-delivery report attached to him, that was NOT
resolved. (For simplicity’s sake, we just ignore all other conditions.)
So I need two queries:
- Select all subscribes that are eligible.
- Select all subscribers that are not eligible.
Query two was managable and rather easy:
SELECT DISTINCT Subscriber.id FROM Subscriber INNER JOIN ShippingAddress ON (Subscriber.id = ShippingAddress.subscriber_id) INNER JOIN NonDeliveryReport ON (ShippingAddress.id = NonDeliveryReport.shipping_address_id) WHERE NonDeliveryReport.resolved IS NULL;
But query 1 kills me. I am stuck on this since last week and just can’t get it to work. I hope you could help me with that.
This isn’t part of my main question, but any thoughs (in form of comments pls) about my database design are welcome. I was already thinking about adding a field
deliverable (bool) to
Subscriber and just fill in the value programmatically, when importing the NDRs, but am hesitant because that’d probably defeat the purpose of database normalization.
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!