Answer the question
In order to leave comments, you need to log in
How to combine a request?
There is a request like this:
SELECT sum(money) FROM `accounts` WHERE date >= CURDATE() AND tel_id = 1234 AND type = 1 AND status = 1
SELECT sum(money) FROM `accounts` WHERE date >= CURDATE() AND tel_id IN (1542, 6624, 2524) AND type = 1 AND status = 1
Answer the question
In order to leave comments, you need to log in
SELECT T1.tel_id, T1.sum1, T2.sum2
FROM
(SELECT tel_id, sum(money) AS sum1
FROM accounts
WHERE date >= CURDATE() AND tel_id = 1234 AND type = 1 AND status = 1
) T1,
(SELECT tel_id, sum(money) AS sum2
FROM accounts
WHERE date >= CURDATE() AND tel_id IN (1542, 6624, 2524) AND type = 1 AND status = 1
) T2
WHERE T2.tel_id = T1.tel_id
You don't need to merge anything, joining tables on itself is bad practice and slow queries. It makes no sense, there will be no gain in speed, and the logic of the request through the fifth point. Make 2 requests and combine data in php, then everything will work quickly and logically. Use KISS.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question