It is necessary to combine the result from two tables.

(SELECT 0 as conversions, SUM(clicks) as clicks FROM general_report WHERE _offer_id = 1043 AND _aff_id = 9 AND (`date_time` BETWEEN '2017-05-24' AND '2017-05-24')) UNION (SELECT COUNT(*) as conversions, 0 as clicks FROM conversion_report WHERE _offer_id = 1043 AND _aff_id = 9 AND (DATE(conversion_time) BETWEEN '2017-05-24' AND '2017-05-24')) 

At the exit I get

 +-------------+--------+ | conversions | clicks | +-------------+--------+ | 0 | 1547 | | 24 | 0 | +-------------+--------+ 

I need

 +-------------+--------+ | conversions | clicks | +-------------+--------+ | 24 | 1547 | +-------------+--------+ 

What am I doing wrong ?

  • Most likely at the output you even get two tables. Do not confuse you 0 as conversions in the first and 0 as clicks in the second select? - MihailPw

1 answer 1

You combine 2 queries. The first one will give out the line 0, 1547 , the second - 24, 0 , therefore the result of the execution of the sql query is logical. Do this:

 select sum(conversions), sum(clicks) from ((SELECT 0 as conversions, clicks as clicks FROM general_report WHERE _offer_id = 1043 AND _aff_id = 9 AND (`date_time` BETWEEN '2017-05-24' AND '2017-05-24')) UNION ALL (SELECT 1 as conversions, 0 as clicks FROM conversion_report WHERE _offer_id = 1043 AND _aff_id = 9 AND (DATE(conversion_time) BETWEEN '2017-05-24' AND '2017-05-24'))) t 
  • Here I am stupid :)) thanks a lot, apparently earned - madfan41k