Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:17:26+00:00 2026-06-06T19:17:26+00:00

I am receiving this mysql error and i don’t know why. I am following

  • 0

I am receiving this mysql error and i don’t know why. I am following a tutorial and i have copied the syntax from the video word for word. Can anybody spot whats wrong?

Here is the error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LEFT JOIN ( SELECT post_id, COUNT(comment_id) AS `total_co’ at line 11

     $query = "SELECT 
        `posts`.`post_id`                 AS `id`,
        `posts`.`post_title`              AS `title`,
         LEFT(`posts`. `post_body`, 512)  AS `preview`,
        `posts`.`post_user`               AS `user`,
         DATE_FORMAT(`posts`.`post_date`, '%d/%m/%Y %H:%i:%s') AS `date`,
         `comments`.`total_comments`,
        DATE_FORMAT(`comments`.`last_comment`, '%d/%m/%Y %H:%i:%s') AS `last_comment`

         FROM `posts`, 
         LEFT JOIN (
            SELECT 
                `post_id`,
                COUNT(`comment_id`) AS `total_comments`,
                MAX(`comment_date`) AS `last_comment`
            FROM `comments`
            GROUP BY `post_id` 
         ) AS `comments`
         ON `posts`.`post_id` = `comments`.`post_id` 
         ORDER BY `posts`.`post_date` DESC";

Your help is much appreciated. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:17:28+00:00Added an answer on June 6, 2026 at 7:17 pm

    Remove the comma , at line 10:

    FROM `posts`
         LEFT JOIN 
    

    The correct syntax is:

    FROM  
        <table a>
      LEFT JOIN  
        <table b>
          ON  <join condition>
    

    Unrelated to the problem:

    • For a (small) improvement on efficiency, change the COUNT(comment_id) to:

              COUNT(*) AS total_comments,
      
    • You could also add a (post_id, comment_date) index on table comments

    • In the main SELECT list, if you prefer to have 0s than NULLs for posts without comments, change comments.total_comments, to:

      COALESCE(comments.total_comments, 0) AS total_comments,
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am receiving a syntax error: MySQL said: Documentation #1064 - You have an
I'm receiving the following error with this page while trying to retrieve information from
I'm receiving data from GPS and store them in MySQL database. I have following
I am receiving this error. I have no clue as to why it would
I'm working through the Django tutorial and receiving the following error when I run
This is the error i'm receiving 1064 - You have an error in your
I don't know if I have got this correct but what I am trying
I have built a site using Django and I am receiving this annoying error
I'm following this tutorial http://codemagento.com/2011/03/creating-custom-magento-reports/ creating the simple report module. I have all the
I'm receiving this error in my Linq statement --- Cannot implicitly convert type 'System.Collections.Generic.IEnumerable'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.