mysql_query () does not parse SQL properly

Source: Internet
Author: User
An SQL statement that runs directly into MySQL is normal.
But the result of running this SQL with PHP mysql_query is different, will it be the reason why mysql_query cannot parse?




SQL is as follows:



INSERT into Analysis.caomei_of_list_pvuv  (region,isp,uv,pv,date)  SELECTTB2.REGION,TB2.ISP,TB2.UV,TB2.PV, ' 2014-05-14 ' as Date   from   (SELECT tb.region,tb.isp, COUNT (Tb.mac) as Uv,sum (Tb.mac_num) as PV from  caomei_ 20140515.caomei_1 as TB WHERE tb.date = ' 2014-05-14 '  GROUP by Tb.region, Tb.isp) as TB2 left  JOIN (SELECT tb6.reg ION,TB6.ISP,TB6.UV,TB6.PV from Analysis.caomei_of_list_pvuv as Tb6 WHERE tb6.date= ' 2014-05-14 '   ) as TB1 on Tb2.region = tb1.region WHERE tb1.region is null and tb2.region are not  null;


Reply to discussion (solution)

Nsert into Analysis.caomei_of_list_pvuv
(region,isp,uv,pv,date)
SELECT
TB2.REGION,TB2.ISP,TB2.UV,TB2.PV, ' 2014-05-14 ' as Date
From
(
SELECT
Tb.region,tb.isp, COUNT (TB.MAC) as UV,
SUM (Tb.mac_num) as PV
From
Caomei_20140515.caomei_1 as TB
WHERE
tb.date = ' 2014-05-14 '
GROUP by Tb.region, Tb.isp
) as TB2
Left JOIN
(
SELECT
Tb6.region,tb6.isp,tb6.uv,tb6.pv
From
Analysis.caomei_of_list_pvuv as Tb6
WHERE
Tb6.date= ' 2014-05-14 '
) as Tb1

On tb2.region = Tb1.region
WHERE
Tb1.region is NULL
And Tb2.region is not NULL

This is not allowed.

Nsert into Analysis.caomei_of_list_pvuv
(region,isp,uv,pv,date)
SELECT
TB2.REGION,TB2.ISP,TB2.UV,TB2.PV, ' 2014-05-14 ' as Date
From
(
SELECT
Tb.region,tb.isp, COUNT (TB.MAC) as UV,
SUM (Tb.mac_num) as PV
From
Caomei_20140515.caomei_1 as TB
WHERE
tb.date = ' 2014-05-14 '
GROUP by Tb.region, Tb.isp
) as TB2
Left JOIN
(
SELECT
Tb6.region,tb6.isp,tb6.uv,tb6.pv
From
Analysis.caomei_of_list_pvuv as Tb6
WHERE
Tb6.date= ' 2014-05-14 '
) as Tb1

On tb2.region = Tb1.region
WHERE
Tb1.region is NULL
And Tb2.region is not NULL

This is not allowed.



But MySQL is able to perform normally to get results.
PHP can also execute, but the result is offset!!

The question is not whether there is grammatical error
But the control logic is the cyclic paradox.

But I think that there should be no logical problem ah, first find out the results. Then write the results to yourself.
The most important is that the results of PHP run different from the results of MySQL run!!

is to try to avoid this logic, or else there will be such unexpected results.

INSERT into a (version) SELECT version from a WHERE id=1;

Assuming that the first execution inserts 1 strips
Then the second execution will insert 2.
The third execution will insert 4.

I know...................................

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.