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 701903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:39:42+00:00 2026-05-14T03:39:42+00:00

I usually use ORM instead of SQL and I am slightly out of touch

  • 0

I usually use ORM instead of SQL and I am slightly out of touch on the different JOINs…

SELECT `order_invoice`.*
     , `client`.*
     , `order_product`.*
     , SUM(product.cost) as net 
  FROM `order_invoice` 
  LEFT JOIN `client` 
    ON order_invoice.client_id = client.client_id 
  LEFT JOIN `order_product` 
    ON order_invoice.invoice_id = order_product.invoice_id 
  LEFT JOIN `product` 
    ON order_product.product_id = product.product_id 
 WHERE (order_invoice.date_created >= '2009-01-01') 
   AND (order_invoice.date_created <= '2009-02-01') 
 GROUP BY `order_invoice`.`invoice_id`

The tables/ columns are logically names… it’s an shop type application… the query works… it’s just very very slow…

I use the Zend Framework and would usually use Zend_Db_Table_Row::find(Parent|Dependent)Row(set)('TableClass') but I have to make lots of joins and I thought it’ll improve performance by doing it all in one query instead of hundreds…

Can I improve the above query by using more appropriate JOINs or a different implementation? Many thanks.

  • 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-14T03:39:42+00:00Added an answer on May 14, 2026 at 3:39 am

    The query is wrong, the GROUP BY is wrong. All columns in the SELECT-part that are not in an aggregate function, have to be in the GROUP BY. You mention only one column.

    Change the SQL Mode, set it to ONLY_FULL_GROUP_BY.

    When this is done and you have a correct query, use EXPLAIN to find out how the query is executed and what indexes are used. Then start optimizing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually use midentify, which spits out a nicely formatted string, that is easy
I usually use ClickOnce as my publication method, but I hate sending a bunch
I usually use NUnit as a UnitTest Framework ,however where I work now they
I usually use a construct like this to apply filters to columns: CREATE TABLE
I usually use MySQL Query Browser for my queries, but I always run into
I usually use the UUID class to generate unique IDs. This works fine if
When I need to disable/re-enable validator I usually use jQuery code like so: ValidatorEnable($('[id*=DueDateRequiredValidator]')[0],
I need to retrieve a web content. I usually use wget but it's giving
A question of ColdFusion ORM We are using ColdFusion 9 for the past 6
I have a list of Person s each which have multiple fields that I

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.