I have an application where a user adds things they’ve bought to their account. They create a list name e.g. my ebay purchaes, then add what they’ve bought in the past.
When they create the list they can choose whether its public or not, and this is where i’m struggling.
I need to show a list of products and who listed them onto which list, but, if they were listed onto a private list then show the users name as private and the list name as private
4 tables:
products
prod_id store_name product user_id
------- --------- ------- -------
1 ebay chair 1002
2 amazon desk 1000
3 ebay lamp 1001
users
user_id name
------- -------
1000 john
1001 mark
1002 sue
user_onto_list
user_onto_list_id user_id list_id
------- --------- -------
1 1000 11
2 1001 12
3 1002 10
list_detail
list_id visibility list_name
------- ------- ---------
10 open myEbayList
11 open myAmazonList
12 private myPrivateList
so the result would be:
product listed_by list_name
------- --------- ---------
chair sue myEbayList
desk john myAmazonList
lamp PRIVATE PRIVATE
Is this possible in one query or would you redesign how the data was stored to make it simpler? I’d rather keep it like this so if e.g sue decided to make her myEbatList private at any time the products would not show as being listed by her and mark may decide to make his list public.
Advice appreciated
EDIT: I’ve included the logic regarding privacy in CASE statements as part of the SELECT, as this does not interfere with the JOIN criteria, it’s only display information. Alternatively you could build that logic into some kind of UNION structure in a derived table and then join to that, but that would probably be less inefficient.