我想使用多个表来获取最近的帖子(Q)和用户名(句柄),但是当我尝试使用此代码时,它给出了错误
表名qa_posts和qa_users需要连接来自qa_posts的userid来处理来自qa_users
SELECT *
FROM qa_posts, qa_users
WHERE type="Q" AND qa_posts.userid = "qa_users.handle"
ORDER BY created DESC
LIMIT 5
错误信息
SELECT *
FROM qa_posts, qa_users
WHERE qa_posts.userid = "qa_users.handle"
ORDER BY created DESC
LIMIT 5
Error 1052: Column 'created' in order clause is ambiguous
实际代码
qa_db_connection();
$query_post = qa_db_query_raw('
SELECT *
FROM qa_posts, qa_users
WHERE type="Q" AND qa_posts.userid = "qa_users.handle"
ORDER BY created DESC
LIMIT 5
') or die(mysql_error());
while($row = mysql_fetch_array($query_post)) {
echo $row['title'];
echo '<span style="font-size:65%;font-style:italic">'.$row['created'].'</span>';
echo '<br/>';
}
有关表结构,请参阅此图像