我在将 COUNT 添加到我的查询时遇到问题。
查询工作正常,但只要我添加COUNT(*) AS totalNum
,我就会从每个表中得到 1 个结果
$query = "(SELECT 'table1' AS tablename, navid, thumb, title, longText, clicks AS allClicks, COUNT(*) AS totalNum
FROM table1
WHERE $column=1
AND enabled=1)
UNION DISTINCT
(SELECT 'table2' AS tablename, navid, thumb, title, longText, clicks AS allClicks, COUNT(*) AS totalNum
FROM table2
WHERE $column=1
AND enabled=1)
ORDER BY allClicks DESC";
while ($row = mysql_fetch_assoc($result)){
$navid = $row['navid'];
$thumb = $row['thumb'];
$tablename = $row['tablename'];
$title = strtoupper($row['title']);
etc...
}
问题:将count(*)添加到我的联接查询中的最佳方法是什么?