Jump to content
  • 0

Trying to make a complex View (3 tables, 2 outer joins) and struggling


DaveS

Question

I'm trying to create a View across 3 tables.  Let's say I'm having a dinner party and I have the tables
a. Guests
b. Food Items
c.  Exclusions (this is a list of Guest / Food Combinations that are not valid - e.g., guest is allergic to this item).

I'm trying to create a view that has every combination of Guests and Foods, and includes Exclusions if it exists and matches the combination of guest and food.  

Would love to get some help with this - have been wrestling with every combination of inner and outer join I can think of and I'm not getting there.  

It seems like this shouldn't be that hard, but I either get only rows with C or I get a single exclusion matching to a bunch of records it shouldn't.

Thanks in advance

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hello @DaveS,

FYI: Cross Join is extremely helpful for some use cases. Actually, it can be the only solution that helps to achieve the result (as your use case).

However, since it creates all possible combinations, it is considered to be rather slow. So, just be aware of the slow View. At least, when it is opened for the first time, after that on the back end the query and values should be cached.
Here is the helpful external article https://www.sqlshack.com/sql-cross-join-with-examples/

Link to comment
Share on other sites

  • 0

Thanks, @CoopperBackpack - I considered that and agree.  I don't have a sense for how big it has to be to be a problem.  One table has about 2500 records and is unlikely to see material growth.  The other is (basically) a b2b customer table.  The result set could be millions of records... but not until I get thousands of (b2b) customers.  I'm thinking it would be a good problem to have...  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...