order-by

zbsbpyhn  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(329)

我想用order by语句提供我的top结果。

$sql_ins = "select user_first_name, user_last_name, user_id from user 
            INNER JOIN xyz on user_id=s_id 
            where (s_id='".$_SESSION['user']."' OR r_id='".$_SESSION['user']."')
              AND user_id!='".$_SESSION['user']."' group by user_id

            UNION

            SELECT user_first_name, user_last_name, user_id from user 
            INNER JOIN xyz on user_id=r_id 
            WHERE (r_id='".$_SESSION['user']."' OR s_id='".$_SESSION['user']."')
              AND user_id!='".$_SESSION['user']."' 

            GROUP BY user_id";

我想按order by id desc获取输出,但输出是一个错误。

xsuvu9jc

xsuvu9jc1#

使用这个查询它对我有用。。。。

SELECT * 
FROM (SELECT content_update.id as id, 
             content_update.course_id as course_id, 
             content_update.status as status, 
             content_update.title as title, 
             content_update.img_src as img, 
             content_update.entry_date as entry_date 
      FROM content_update 

      UNION ALL 

      SELECT video_update.id as id, 
             video_update.course_id as course_id, 
             video_update.status as status,
             video_update.title as title, 
             video_update.video_link as img, 
             video_update.entry_date as entry_date 
      FROM video_update ) results 

ORDER BY entry_date DESC

相关问题