当自己运行以下每个 SELECT(没有 UNION)时,我得到了预期的结果。使用 UNION 时我没有得到任何结果。
任何想法为什么这不起作用?
$query = "
(SELECT * FROM projects WHERE public='1')
UNION
(SELECT * FROM projects JOIN project_region ON projects.id_project = project_region.id_project
JOIN user ON user.id_region = project_region.id_region WHERE user.user_id = {$current_user->ID})
UNION
(SELECT * FROM projects JOIN project_user ON projects.id_project = project_user.id_project
WHERE project_user.user_id = {$current_user->ID})
";
$projects = $wpdb->get_results($query);
if ($projects) {
foreach ($projects as $project) {
// output results
}
}