Skip to content
Advertisement

Simple query to join with my booking table without duplicating records for each booking

I have a customer credit table and a booking table, shown below. I’ve executed the following query which works but it’s too simple. I now need to cross join my original query to the booking table so I can check for where the booking status is completed. My second query is wrong because it SUMs the adjustment for each booking.

Initial working query

Query with join

Customer credit

Booking

Advertisement

Answer

Do the sum first and then join:

Note: I suspect that you might want a left join to handle customers with no adjustments.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement