[英]How to use a more complex query inside mysql_query?
I'm trying to use a more complex query through PHP and seem to be having issues. 我正在尝试通过PHP使用更复杂的查询,但似乎遇到了问题。 Here's what I'm trying to do:
这是我想做的事情:
$result = mysql_query('select(select count(*) from tblname where column LIKE xyz) and (select count(*) from tblname2 where column2='Value'));
This doesn't seem to work - any help? 这似乎不起作用-有帮助吗?
That's not valid SQL. 那不是有效的SQL。 If you want the sum of both counts, maybe you mean:
如果您想要两个计数的总和,也许您的意思是:
SELECT SUM(cnt)
FROM
(
SELECT COUNT(*) AS cnt
FROM tblname
WHERE column LIKE xyz
UNION ALL
SELECT COUNT(*) AS cnt
FROM tblname2
WHERE column2 = 'Value'
) x
You're using incorrect syntax, did you try to check the manual first? 您使用的语法不正确,是否尝试过先检查手册? http://dev.mysql.com/doc/refman/5.0/en/subqueries.html
http://dev.mysql.com/doc/refman/5.0/en/subqueries.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.