suppose i have parent channel X which has 4 sub-channels. each sub-channel and parent channel has some videos first sql query returns videos in all sub-channel whose parent is X and second query returns videos whose channel is X. now i want combined result of these two. sum of videos in channel X and videos in all sub-channel of X
$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.";";
You can use an or
condition to combine your queries
$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";
Side note: make sure to sanitize $video_cat_id
or better yet use prepared statements to protect yourself against injection attacks.
I'think you are expecting this.
" Select vibe_videos.* from vibe_videos INNER JOIN vibe_channels ON ( vibe_channels.child_of = vibe_videos.category AND vibe_videos.category = ". $video_cat_id .") or vibe_videos.category = ". $video_cat_id;
"SELECT foo1, foo2, foo3 FROM `vibe_videos` WHERE category = ".$video_cat_id." OR child_of=".$video_cat_id.";
But you should use prepared statements to get rid of potential SQL injections attacks, and avoid selecting * in favor of naming what you are selecting.