How to fix unwanted SQL fanouts? #2693
Unanswered
senorsenorjunior
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Sorry, not super experienced with SQL here so I may be incorrect in saying it's a fanout, but I think that's what it is. Essentially, I have 4 tables in question: one is a bills table, another is a UsersToBills junction table, the third is the users table, and the fourth is an expenses table(I don't have a junction table for expenses because I store the billId inside the Expenses schema). To keep it brief, a bill can have both multiple users and multiple expenses associated with it. What I'm trying to do is query an array of all the bills, where each bill has
its information along with the arrays of both users and expenses associated with it: In psuedocode, this is my desired structure:
Now, here's the problem: lets say a bill has two users and one expense associated with it. The way this query currently works, it correctly returns the two users, but then it also returns 2 copies of the one expense (I'm guessing that's because there are two users?) Obviously, what I would want, is for it to only return the unique number of expenses. Anyways, any help with getting this query correct would be greatly appreciated, I've been bashing my head against the wall for the last hour trying to figure it out and I don't know where to start. The query is attached directly below. Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions