Skip to content
Advertisement

How to combine 4 sql queries into a single query with good performance?

I have a problem to solve. First I split this problem into parts and so I wrote four queries separately but now I need to put them together as if it were a single call to return a single result. How can I do this?

1) I select purchases according to branch and store

2) I validate if the promotional period of the purchase is within the current date (today)

3) From the purchase code, I check which products are active

4) Finally, I return some fields according to the customer id

Advertisement

Answer

Have you tried below query? I’ve assumed you want INNER JOIN for all the tables, and CD_PURCHASE is common link in all the tables, and CD_PRODUCT is the link between TB_PURCHASE_PRODUCT and TB_PURCHASE_SALES.

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