Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 从Select语句中选择:每个派生表都必须有自己的别名_Mysql_Sql_Select - Fatal编程技术网

Mysql 从Select语句中选择:每个派生表都必须有自己的别名

Mysql 从Select语句中选择:每个派生表都必须有自己的别名,mysql,sql,select,Mysql,Sql,Select,我需要按ASC顺序检索最后3行,因此这里是最后一个查询: SELECT c.comment_id,c.comment_message,c.comment_date,u.user_id,u.first_name,u.last_name,p.profile_picture_path FROM (SELECT c.comment_id,c.comment_message,c.comment_date,u.user_id,u.first_name,u.last_name,p.profile

我需要按ASC顺序检索最后3行,因此这里是最后一个查询:

SELECT c.comment_id,c.comment_message,c.comment_date,u.user_id,u.first_name,u.last_name,p.profile_picture_path 
FROM 
     (SELECT c.comment_id,c.comment_message,c.comment_date,u.user_id,u.first_name,u.last_name,p.profile_picture_path 
      FROM posts_comments c,users u,users_profile_pictures p 
      WHERE c.user_id = u.user_id AND u.user_id = p.user_id AND c.post_id = '82' 
      ORDER BY c.comment_date DESC 
      LIMIT 3) 
ORDER BY c.comment_date ASC

我知道这里有点不对劲,我收到了这个错误:每个派生表都必须有自己的别名。当适当的表指出列时,如何从select语句中选择列?意思是,如何选择c.comment\u id?

现在我得到了以下信息:“字段列表”中的未知列“c.comment\u id”:很抱歉输入错误,请再次尝试更新的查询。c不再有效,因为它包含在子查询中。它起作用了:D但为什么它需要别名?它将给出名称来标识子查询。现在我得到了以下信息:“字段列表”中的未知列“c.comment\u id”:很抱歉输入错误,请重试更新的查询。c不再有效,因为它包含在子查询中。它可以工作:D但为什么它需要别名?它将给出名称来标识子查询。
SELECT  comment_id,
        comment_message,
        comment_date,
        user_id,
        first_name,
        last_name,
        profile_picture_path
FROM (
        SELECT  c.comment_id,
                c.comment_message,
                c.comment_date,
                u.user_id,
                u.first_name,
                u.last_name,
                p.profile_picture_path
        FROM    posts_comments c,
                users u,
                users_profile_pictures p
        WHERE   c.user_id = u.user_id
                AND u.user_id = p.user_id
                AND c.post_id = '82'
        ORDER BY c.comment_date DESC 
        LIMIT 3
    ) subA -- <<==  put alias here
           -- the purpose of the alias is to supply an identification 
           -- for the subquery
ORDER BY comment_date ASC
 SELECT x.comment_id
      , x.comment_message
      , x.comment_date
      , x.user_id
      , x.first_name
      , x.last_name
      , x.profile_picture_path 
   FROM 
      ( SELECT c.comment_id
             , c.comment_message
             , c.comment_date
             , u.user_id
             , u.first_name
             , u.last_name
             , p.profile_picture_path 
          FROM posts_comments c
          JOIN users u
            ON u.user_id = c.user_id 
          JOIN users_profile_pictures p 
            ON p.user_id = u.user_id 
         WHERE c.post_id = 82 
         ORDER 
            BY c.comment_date DESC 
         LIMIT 3
      ) x 
  ORDER 
     BY x.comment_date ASC;