Mysql
 sql >> डेटाबेस >  >> RDS >> Mysql

SQL क्वेरी की लंबाई की व्यावहारिक सीमा (विशेषकर MySQL)

आपकी क्वेरी को पढ़कर मैं आरपीजी खेलना चाहता हूं।

यह निश्चित रूप से बहुत लंबा नहीं है। जब तक वे अच्छी तरह से स्वरूपित होते हैं, मैं कहूंगा कि व्यावहारिक सीमा लगभग 100 लाइनें है। उसके बाद, बेहतर होगा कि आप अपनी नज़रों को क्रॉसिंग से बचाने के लिए सबक्वायरी को व्यू में तोड़ दें।

मैंने कुछ प्रश्नों के साथ काम किया है जो 1000+ लाइनें हैं, और इसे डीबग करना मुश्किल है।

वैसे, क्या मैं एक सुधारित संस्करण का सुझाव दे सकता हूं? यह ज्यादातर स्वरूपण के महत्व को प्रदर्शित करने के लिए है; मुझे विश्वास है कि इसे समझना आसान होगा।

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.
*/


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. पायथन:MySQL से जुड़ने और प्रश्नों को निष्पादित करने का सबसे अच्छा अभ्यास और सबसे सुरक्षित तरीका

  2. MySQL विशेषक असंवेदनशील खोज (स्पेनिश उच्चारण)

  3. मैसकल - यूनिक इंडेक्स के साथ संयुक्त कॉलम की डुप्लिकेट प्रविष्टियों को रोकना

  4. दो तालिकाओं के लिए कई स्थितियों के आधार पर घटनाओं की गणना करें

  5. जॉइन क्वेरीज़ बनाम मल्टीपल क्वेश्चन