I have a simple customers
table designed this way (I report only some fields, the ones regarding this qeustions):
+ ----------- + --------------- + ---------------- +
+ customer_id + invoice_address + ship_address +
+ ----------- + --------------- + ---------------- +
+ 33 + 234, Walnut Ave + null +
+ ----------- + --------------- + ---------------- +
+ 47 + 66, Smart Ave + null +
+ ----------- + --------------- + ---------------- +
+ 47 + 4, Cool Ave + 45, Dark Street +
+ ----------- + --------------- + ---------------- +
Rows with null ship_address means we must use customer's invoice address also for shipping.
1st question: is this a good enough design, or should all the null
ship_address
fields be filled with the invoice address (even if identical) and not left null
.
2nd question: keeping such a design (even in case it's bad design), how do I create a SELECT query (if it's possible) that returns always one single address for each row: the ship_address
when NOT null
, otherwise just the invoice_address
, something like:
SELECT CONCAT_IF_SHIP_ADDRESS_NOT_NULL_OTHERWISE_USE_ONLY_SHIP_ADDRESS(invoice_address, ship_address) AS address FROM customers;
Query for MySQL DB.
Thanks,