gpt4 book ai didi

php - 两个 MySQL 查询的合并结果

转载 作者:行者123 更新时间:2023-11-29 11:43:01 24 4
gpt4 key购买 nike

假设我有父 channel X,它有 4 个子 channel 。每个子 channel 和父 channel 都有一些视频,第一个sql查询返回父 channel 为X的所有子 channel 中的视频,第二个查询返回 channel 为X的视频。现在我想要这两个的组合结果。 X channel 的视频和X所有子 channel 的视频之和

$sql1="SELECT * FROM vibe_videos where category in (SELECT cat_id FROM vibe_channels where child_of=".$video_cat_id.");";
$sql2 = "SELECT * FROM vibe_videos where category = ".$video_cat_id.";";

最佳答案

您可以使用条件来组合您的查询

$sql1="SELECT * FROM vibe_videos where 
category in (SELECT cat_id FROM vibe_channels where child_of=$video_cat_id)
or category = $video_cat_id";

旁注:确保清理 $video_cat_id 或更好地使用准备好的语句来保护自己免受注入(inject)攻击。

关于php - 两个 MySQL 查询的合并结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35441432/

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