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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:19:15+00:00 2026-05-10T15:19:15+00:00

Is it particularly bad to have a very, very large SQL query with lots

  • 0

Is it particularly bad to have a very, very large SQL query with lots of (potentially redundant) WHERE clauses?

For example, here’s a query I’ve generated from my web application with everything turned off, which should be the largest possible query for this program to generate:

SELECT *  FROM 4e_magic_items  INNER JOIN 4e_magic_item_levels    ON 4e_magic_items.id = 4e_magic_item_levels.itemid  INNER JOIN 4e_monster_sources    ON 4e_magic_items.source = 4e_monster_sources.id  WHERE (itemlevel BETWEEN 1 AND 30)     AND source!=16 AND source!=2 AND source!=5    AND source!=13 AND source!=15 AND source!=3    AND source!=4 AND source!=12 AND source!=7    AND source!=14 AND source!=11 AND source!=10    AND source!=8 AND source!=1 AND source!=6    AND source!=9  AND type!='Arms' AND type!='Feet'    AND type!='Hands' AND type!='Head'    AND type!='Neck' AND type!='Orb'    AND type!='Potion' AND type!='Ring'    AND type!='Rod' AND type!='Staff'    AND type!='Symbol' AND type!='Waist'    AND type!='Wand' AND type!='Wondrous Item'    AND type!='Alchemical Item' AND type!='Elixir'    AND type!='Reagent' AND type!='Whetstone'    AND type!='Other Consumable' AND type!='Companion'    AND type!='Mount' AND (type!='Armor' OR (false ))    AND (type!='Weapon' OR (false ))   ORDER BY type ASC, itemlevel ASC, name ASC 

It seems to work well enough, but it’s also not particularly high traffic (a few hundred hits a day or so), and I wonder if it would be worth the effort to try and optimize the queries to remove redundancies and such.

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

    Reading your query makes me want to play an RPG.

    This is definitely not too long. As long as they are well formatted, I’d say a practical limit is about 100 lines. After that, you’re better off breaking subqueries into views just to keep your eyes from crossing.

    I’ve worked with some queries that are 1000+ lines, and that’s hard to debug.

    By the way, may I suggest a reformatted version? This is mostly to demonstrate the importance of formatting; I trust this will be easier to understand.

    select *   from   4e_magic_items mi  ,4e_magic_item_levels mil  ,4e_monster_sources ms where mi.id = mil.itemid   and mi.source = ms.id   and itemlevel between 1 and 30   and source not in(16,2,5,13,15,3,4,12,7,14,11,10,8,1,6,9)     and type not in(                   'Arms' ,'Feet' ,'Hands' ,'Head' ,'Neck' ,'Orb' ,                   'Potion' ,'Ring' ,'Rod' ,'Staff' ,'Symbol' ,'Waist' ,                   'Wand' ,'Wondrous Item' ,'Alchemical Item' ,'Elixir' ,                   'Reagent' ,'Whetstone' ,'Other Consumable' ,'Companion' ,                   'Mount'                  )   and ((type != 'Armor') or (false))   and ((type != 'Weapon') or (false)) order by   type asc  ,itemlevel asc  ,name asc  /* Some thoughts: ============== 0 - Formatting really matters, in SQL even more than most languages. 1 - consider selecting only the columns you need, not '*' 2 - use of table aliases makes it short & clear ('MI', 'MIL' in my example) 3 - joins in the WHERE clause will un-clutter your FROM clause 4 - use NOT IN for long lists 5 - logically, the last two lines can be added to the 'type not in' section.     I'm not sure why you have the 'or false', but I'll assume some good reason     and leave them here. */ 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 84k
  • Answers 84k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I agree with the other answerers suggesting you just do… May 11, 2026 at 5:04 pm
  • Editorial Team
    Editorial Team added an answer LastWriteTime in the System.IO.FileInfo namespace. FileInfo fi1 = new FileInfo(path);… May 11, 2026 at 5:04 pm
  • Editorial Team
    Editorial Team added an answer if ($res) should work fine to check if it's a… May 11, 2026 at 5:04 pm

Related Questions

Theoretically, the end user should never see internal errors. But in practice, theory and
My question is how does one abstract a database connection from the model layer
I am using a particularly slow virtual web host (name withheld!) where disk performance
Recently, I read an article entitled SATA vs. SCSI reliability . It mostly discusses

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.