gpt4 book ai didi

php - 查询未从两个表中获取数据

转载 作者:行者123 更新时间:2023-11-29 21:11:23 26 4
gpt4 key购买 nike

我正在尝试获取两个表中存在的行数。涉及的两个表是:

  • flaged_posts:有 3 行。
  • flaged_comments:有 1 行。

这是我所拥有的:

$all_flagged_posts = mysqli_query ($connect, "SELECT * FROM flagged_comments c LEFT JOIN flagged_posts p ON c.id AND p.id");
$num_of_total_flagged_posts = mysqli_num_rows ($all_flagged_posts);
echo $num_of_total_flagged_posts;

但是 echo 产生的结果是 3,而它应该是 4

最佳答案

由于您想要不进行任何关系检查的行数 - 您可以使用 union

select sum(cnt) as total_count
from
(
select count(*) as cnt from flagged_comments
union all
select count(*) from flagged_posts
) tmp

关于php - 查询未从两个表中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36337077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com