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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:42:42+00:00 2026-05-16T15:42:42+00:00

Here’s my query, it is fairly straightforward: SELECT INVOICE_ITEMS.II_IVNUM, INVOICE_ITEMS.IIQSHP FROM INVOICE_ITEMS LEFT JOIN

  • 0

Here’s my query, it is fairly straightforward:

SELECT
    INVOICE_ITEMS.II_IVNUM, INVOICE_ITEMS.IIQSHP
FROM
    INVOICE_ITEMS
LEFT JOIN
    INVOICES
ON 
    INVOICES.INNUM = INVOICE_ITEMS.II_INNUM
WHERE
    INVOICES.IN_DATE
BETWEEN
    '2010-08-29' AND '2010-08-30'
;

I have very limited knowledge of SQL, but I’m trying to understand some of the concepts like subqueries and the like. I’m not looking for a redesign of this code, but rather an explanation of why it is so slow (600+ seconds on my test database) and how I can make it faster.

From my understanding, the left join is creating a virtual table and populating it with every result row from the join, meaning that it is processing every row. How would I stop the query from reading the table completely and just finding the WHERE/BETWEEN clause first, then creating a virtual table after that (if it is possible)?

How is my logic? Are there any consistently recommended resources to get me to SQL ninja status?

Edit: Thanks everyone for the quick and polite responses. Currently, I’m connecting over ODBC to a proprietary database that is used in the rapid application development framework called OMNIS. Therefore, I really have no idea what sort of optimization is being run, but I believe it is based loosely on MSSQL.

  • 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-16T15:42:43+00:00Added an answer on May 16, 2026 at 3:42 pm

    I would rewrite it like this, and make sure you have an index on i.INNUM, ii.INNUM, and i.IN_DATE. The LEFT JOIN is being turned into an INNER JOIN by your WHERE clause, so I rewrote it as such:

    SELECT ii.II_IVNUM, ii.IIQSHP 
    FROM INVOICE_ITEMS ii
    INNER JOIN INVOICES i ON i.INNUM = ii.II_INNUM 
    WHERE i.IN_DATE BETWEEN '2010-08-29' AND '2010-08-30' 
    

    Depending on what database you are using, what may be happening is all of the records from INVOICE_ITEMS are being joined (due to the LEFT JOIN), regardless of whether there is a match with INVOICE or not, and then the WHERE clause is filtering down to the ones that matched that had a date within range. By switching to an INNER JOIN, you may make the query more efficient, by only needing to apply the WHERE clause to INVOICES records that have a matching INVOICE_ITEMS record.

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

Sidebar

Related Questions

Here's my working query: SELECT d.*, g.name game, (SELECT GROUP_CONCAT(p.name) FROM shows_players p LEFT
Here is my query: SELECT * FROM [GeoName] WHERE ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long)) < 0.005 ORDER BY
Here's a query that works fine: SELECT rowid as msg_rowid, a, b, c FROM
Here is my query: SELECT p.Company , p.Project_ID , p.Name as 'Project_Name' , p.Company
Here is my SQL: SELECT COUNT(id), CONCAT(YEAR(created_at), '-', MONTH(created_at), '-', DAY(created_at)) FROM my_table GROUP
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here is my query. Its intention is allow access to properties of the animals
Here is a app contorller directory from Rails project doing a self study for
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is the issue I am having: I have a large query that needs

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.