按sql查询错误排序

时间:2014-02-06 04:35:14

标签: mysql sql database

$post_items = $db->query("SELECT post_id,content,date,category_id 
        FROM post_items JOIN user ON(post_items.user_id = user.user_id) WHERE post_items.user_id =" . $userid)

如何在我的案例中包含订单?我试过了

$post_items = $db->query("SELECT post_id,content,date,category_id 
        FROM post_items JOIN user ON(post_items.user_id = user.user_id) WHERE post_items.user_id =" . $userid ."order by post_id");

3 个答案:

答案 0 :(得分:0)

order之前需要一个空格:

." order by post_id"

答案 1 :(得分:0)

请在字段和order关键字之间应用空格,如果columnaname在使用join的查询中是ambiguse,也请使用tablename:

$post_items = $db->query("SELECT post_id,content,date,category_id 
        FROM post_items inner JOIN user ON post_items.user_id = user.user_id  
         WHERE post_items.user_id =" . $userid ." order by post_items.post_id ");

答案 2 :(得分:-1)

您只需在“ORDER BY post_id”之前添加一个空格即可成为“ORDER BY post_id”。