#1248 - Every derived table must have its own alias ,

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kelvinejimogu
    New Member
    • Oct 2012
    • 2

    #1248 - Every derived table must have its own alias ,

    I'm getting error #1248 - Every derived table must have its own alias ,
    below is the full msql statement please Help Im newbie many thanks.

    Code:
    SELECT `Posts`.`Post_id` AS `posts_id`, `Posts`.`title` AS `title`, LEFT(`Posts`.`body`, 512) AS                             `preview`, `comments`.`total_comments` AS `total_comments`, `category`.`Cat_id` AS                             `category_id`, `body`,`category`.`Cat_name`, DATE_FORMAT(`comments`.`last_comments`,                             `%d/%m/%y %H:%i:%s`) AS `last_comments`
    							FROM `Posts`
                                INNER JOIN `category` ON `category`.`Cat_id` = `Posts`.`Cat_id`
    							LEFT JOIN (SELECT `Post_id`, COUNT(`Comm_id`) AS `total_comments`, MAX(`comm_date`) AS `last_comment` FROM `comments`) GROUP BY `comments`.`Post_id` AS `comments`"
    Last edited by Rabbit; Oct 4 '12, 06:49 PM. Reason: Please use code tags when posting code.
  • rpnew
    New Member
    • Aug 2007
    • 189

    #2
    Hi Kelvinejimogu,

    This part in your query should have alias

    Code:
    SELECT `Post_id`, COUNT(`Comm_id`) AS `total_comments`, MAX(`comm_date`) AS `last_comment` FROM `comments
    Like
    Code:
    (SELECT `Post_id`, COUNT(`Comm_id`) AS `total_comments`, MAX(`comm_date`) AS `last_comment` FROM `comments) tab1
    BTW I don't see condition for your LEFT join either on which you are joining with this query

    Comment

    • kelvinejimogu
      New Member
      • Oct 2012
      • 2

      #3
      Thanks guys it now working as it should be here is the full SQL
      Code:
      SELECT `Posts`.`Post_id` AS `posts_id`, `Posts`.`title` AS `title`, LEFT(`Posts`.`body`, 512) AS                             `preview`, `comments`.`total_comments` AS `total_comments`, `category`.`Cat_id` AS `category_id`, `body`,`category`.`Cat_name`, DATE_FORMAT(`comments`.`last_comments`, '%d/%m/%Y %H:%i:%s') AS `last_comments`
      							FROM `Posts`
                                  INNER JOIN `category` ON `category`.`Cat_id` = `Posts`.`Cat_id`
      							LEFT JOIN (SELECT `Post_id`, COUNT(`Comm_id`) AS `total_comments`, MAX(`comm_date`) AS `last_comments` FROM `comments` GROUP BY `comments`.`Post_id`) AS `comments` ON `Posts`.`Post_id` = `comments`.`Post_id` ORDER BY `Post_date`

      Comment

      • rpnew
        New Member
        • Aug 2007
        • 189

        #4
        Glad that it helped..

        Comment

        Working...