我正在尝试优化sql查询。每当我尝试创建临时sql表时,输出都会显示错误
这是查询代码:
$k_new = mysql_result(mysql_query("CREATE TEMPORARY TABLE IF NOT EXISTS temp1 AS SELECT
MAX(mail.id) AS id
FROM
`mail`
WHERE
mail.`unlink` != '$user[id]'
AND (
mail.`id_kont` = '$user[id]'
)
GROUP BY
IF(mail.`id_user` = '$user[id]',
mail.`id_kont`,
mail.`id_user`)
ORDER BY
NULL;
-该索引是最佳临时表性能所必需的
ALTER TABLE
`temp1`
ADD
INDEX `temp1_idx_id` (`id`);
SELECT
COUNT(*)
FROM
`mail` AS m,
temp1 AS max
WHERE
m.id = max.id
AND m.read = '0'
AND (
m.id_kont = '$user[id]'
)
AND m.unlink != '$user[id]'"), 0);
我希望它是邮件数,但实际输出是:警告:mysql_result()期望参数1为资源,在/var/www/domains/shorena.ru/style/themes/vk/中给出布尔值head.php在333行