Skip to content
Advertisement

Combining MySQL Queries to get total amount

I’m trying to combine the following 2 queries. table_A stores a list of available appointments and number_open is how many open slots there are for a specific appointment, in this case 2020-06-30 AM which has 5 open. table_B contains any dates waiting to be accepted and has a different record for each date request, so in this case, 2 rows sitting there, 2 dates waiting to be accepted. What I’m trying to do is combine both queries to get a list of how many appointments there are left for each slot, so expected results would be table_A.numberopen (5) minus table_B.Count() (2), result = 3 left to allocate. Everything I try results in duplicate records being returned, I can’t seem to narrow it down to just a single total number for that appointment. table_A will always have a record, but table_B may not have any matching records. Thanks in advance for any help you can provide.

Advertisement

Answer

Your question is quite unclear about the join conditions between the two tables, however I suspect that a correlated subquery would do what you want:

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