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

  • Home
  • SEARCH
  • 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 6157701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:49:47+00:00 2026-05-23T20:49:47+00:00

I have quite a long query that is causing me some problems. For the

  • 0

I have quite a long query that is causing me some problems. For the first sub-query I keep getting the error: “MySQL server version for the right syntax to use near ‘SELECT project.project_total_num_hours_quoted FROM project inner join time_recor’ at line 5”.

The subquery in question is:

sum(SELECT
    project.project_total_num_hours_quoted
    FROM
    project inner join time_recording using(project_id)
    WHERE
    project.company_id = company.company_id
    AND project_is_retainer != 1
    AND time_recording.time_recording_event_start_datetime >= '2011-01-01' AND time_recording.time_recording_event_stop_datetime <= '2011-03-01'
    group by project_id
    ) AS hours_quoted,

This returns a set of results. In the larger query I simply want to have the sum.

SELECT 
SUM((unix_timestamp(time_recording.time_recording_event_stop_datetime)-unix_timestamp(time_recording.time_recording_event_start_datetime))/3600) AS total_time, 
company.company_label,

sum(SELECT
project.project_total_num_hours_quoted
FROM
project inner join time_recording using(project_id)
WHERE
project.company_id = company.company_id
AND project_is_retainer != 1
AND time_recording.time_recording_event_start_datetime >= '2011-01-01' AND time_recording.time_recording_event_stop_datetime <= '2011-03-01'
group by project_id
) AS hours_quoted,

(SELECT SUM(project.project_total_num_hours_quoted)
FROM project 
INNER JOIN time_recording ON project.project_id = time_recording.project_id
WHERE time_recording.time_recording_event_start_datetime>='2011-01-01'
AND project_is_retainer!=1
AND time_recording.time_recording_event_stop_datetime<='2011-03-01'
AND project.company_id!=1
) AS total_hours_quoted,

(
SELECT 
SUM((unix_timestamp(time_recording.time_recording_event_stop_datetime)-unix_timestamp(time_recording.time_recording_event_start_datetime))/3600) 
FROM time_recording 
INNER JOIN project ON time_recording.project_id = project.project_id 
WHERE project.company_id!=1 
AND project_is_retainer!=1
AND time_recording.time_recording_event_start_datetime>='2011-01-01'
AND time_recording.time_recording_event_stop_datetime<='2011-03-01'
)
AS total_hours

FROM time_recording 
INNER JOIN project ON time_recording.project_id = project.project_id
INNER JOIN company ON project.company_id = company.company_id
WHERE company.company_id!=1
AND project_is_retainer!=1
AND time_recording.time_recording_event_start_datetime>='2011-01-01'
AND time_recording.time_recording_event_stop_datetime<='2011-03-01'
GROUP BY company.company_id 
ORDER BY total_time desc 
LIMIT 7
  • 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-05-23T20:49:48+00:00Added an answer on May 23, 2026 at 8:49 pm

    In your first subquery, you don’t need the group by if you sum it in the outer query. And you are missing the ON clause.

    SELECT project.project_total_num_hours_quoted
    FROM project inner join time_recording 
    ON project.id=time_recording.project_id
    WHERE
    project.company_id = company.company_id
    AND project_is_retainer != 1
    AND time_recording.time_recording_event_start_datetime >= '2011-01-01' 
    AND time_recording.time_recording_event_stop_datetime <= '2011-03-01'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a backroundrb scheduled task that takes quite a long time to run.
I have quite long query with 'Q()', with Sqlite3 works very well, but with
I am trying to speed up a long running query that I have (takes
I have quite a few RewriteRules in my .htaccess that looks like this RewriteRule
I have quite a few cells that link to other worksheets/books, etc with standard
I have (after quite a bit of work) a web test that will upload
I have a query that I'm executing from a .NET application to a SQL
I have four entities that are involved in a query that I'm having a
I'm trying to retrieve listings that are near a user's current lat/long position. Have
I have quite a large list of words in a txt file and I'm

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.