【发布时间】:2016-05-15 10:54:09
【问题描述】:
我正在尝试加入或合并两个不同结构表的结果,按它们的公共 pubdate 列对它们进行排序,但收到一条错误消息:
“使用的 SELECT 语句的列数不同”
$sql = "
SELECT * FROM news WHERE published='1' AND image!='' AND featured='1'
JOIN
SELECT * FROM videos WHERE published='1'
ORDER BY pubdate DESC
";
$query = mysqli_query($connection, $sql);
while($row = mysqli_fetch_array($query)){
$posttype = $row["posttype"];
$pubdate = $row["pubdate"];
if ($posttype == 'news'){
$content = $row["content"];
$image = $row["image"];
} // end if posttype
if ($posttype == 'videos'){
$description = $row["description"];
} // end if posttype
...
echo ....
} // end while
我如何编辑我的查询,以便我可以运行我的 fetch 数组并在之后检索相应的行(要获取的行然后决定于两个表共享的另一个公共行)?
【问题讨论】:
-
你能给我们展示几行样本表数据和预期的结果吗?
-
感谢大家到目前为止的帮助,我已经编辑了上面的代码以提供有关我想要检索的数据和输出的更多详细信息
标签: mysql sql join mysqli union