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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:14:02+00:00 2026-06-15T04:14:02+00:00

Im writing this complex query to return a large dataset, which is about 100,000

  • 0

Im writing this complex query to return a large dataset, which is about 100,000 records. The query runs fine until i add in this OR statement to the WHERE clause:

AND (responses.StrategyFk = strategies.Id Or responses.StrategyFk IS
Null)

Now i understand that by putting the or statement in there it adds a lot of overhead.

Without that statement and just:

AND responses.StrategyFk = strategies.Id

The query runs within 15 seconds, but doesn’t return any records that didn’t have a fk linking a strategie.

Although i would like these records as well. Is there an easier way to find both records with a simple where statement? I can’t just add another AND statement for null records because that will break the previous statement. Kind of unsure of where to go from here.

Heres the lower half of my query.

FROM 
responses, subtestinstances, students, schools, items,
strategies, subtests

WHERE
subtestinstances.Id = responses.SubtestInstanceFk
AND subtestinstances.StudentFk = students.Id
AND students.SchoolFk = schools.Id
AND responses.ItemFk = items.Id
AND (responses.StrategyFk = strategies.Id Or responses.StrategyFk IS Null)
AND subtests.Id = subtestinstances.SubtestFk
  • 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-15T04:14:03+00:00Added an answer on June 15, 2026 at 4:14 am

    try:

    SELECT ... FROM 
    responses
    JOIN subtestinstances ON subtestinstances.Id = responses.SubtestInstanceFk
    JOIN students ON subtestinstances.StudentFk = students.Id
    JOIN schools ON students.SchoolFk = schools.Id
    JOIN items ON responses.ItemFk = items.Id
    JOIN subtests ON subtests.Id = subtestinstances.SubtestFk
    LEFT JOIN strategies ON responses.StrategyFk = strategies.Id
    

    That’s it. No OR condition is really needed, because that’s what a LEFT JOIN does in this case. Anywhere responses.StrategyFk IS NULL will result in no match to the strategies table, and it wil return a row for that.

    See this link for a simple explanation of joins: http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

    After that, if you’re still having performance issues then you can start looking at the EXPLAIN SELECT ... ; output and looking for indexes that may need to be added. Optimizing Queries With Explain — MySQL Manual

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

Sidebar

Related Questions

I'm writing this query and I'm running into a mental road block. I keep
I am writing a fairly complex iPad app - my first bigger one. This
I'm writing a fairly complex ListView , which (among other things) requires formatting Views
I tried writing this class #include <memory> class ContainerUnique { public: ContainerUnique(void); ~ContainerUnique(void); private:
I've had trouble writing this code. I'm supposed to make a function that can
I am writing this, with continuation to my previous posts... Where to click on
So I've been writing this tool and I am using these Sockets (not these
I am writing this app in windows form c#. When user exit from this
I am writing this JS for CRM 2011, and this error pops out whenever
(I'm writing this in the context of JavaScript, but will accept an algorithmically correct

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.