I have two things to do: optimize table, write a query.
customer
id customer year_in_business is_discountable customers_friend_id
1 a 2 true 2
2 b 3 false 1
3 c 2 true 1
4 d 3 true null
Here customer_friend_id is pointing back to pk(id) of the same table.
product
id product
1 xxx
2 yyy
3 aaaa
customer_product
customer_id product_id
1 2
2 3
3 1
Questions
- How to make these tables flexible or extensible in the future?
- Get Name of each customer that has a friend and the name of that customer’s friend.
Here is one suggestion: remove
customer.customers_friend_idand create a newCustomerFriendtable like so:This will allow customers with more than one friend, and avoids nulls for customers without friends.