æ°èãåºã¾ãï¼ãé人ã«å¦ã¶ SQLå¾¹åºæåæ¸ ç¬¬2çã
æ¬æ¥ãæ°èãçºå£²ã¨ãªãã¾ããæ¬æ¸ã®åçã¯å¦å¥³ä½ã¨ãããã¨ããããè²ã ã¨æ¸ãæã¨ãã¦æªçãªé¨åãå¤ãåºã¦ãã¾ã£ãæ¬ãªã®ã§ããã幸éã«ãé·ãæéèªãã§ããã ãããã¨ã§ãã®ãã³æ¹è¨çã®åè¡ã«ããã¤ãããã¨ãåºæ¥ã¾ããã
ãããã«10å¹´çµéããã¨å 容ãå¤ããªã£ã¦ãããå¤ãã®ã³ã¼ãããªãã¤ã¹ãã¦ãã¾ããç¹ã«åçåè¡æã«ã¯ã¾ã ãµãã¼ããä¸ååã ã£ãã¦ã£ã³ãã¦é¢æ°ããç¾å¨ã§ã¯ä¸»è¦ãªDBMSã§ã¯ã»ã¼å©ç¨ã§ããããã«ãªã£ããã¨ãåãã¦ãå ¨é¢çã«ãããæ¡ç¨ãã¾ãããããã«ããæ§è½ã¨è¡¨ç¾åã両ç«ãããã¢ãã³ãªSQLã³ã¼ãã£ã³ã°ãå¯è½ã«ãªã£ãã®ã§ããã²æ¬æ¸ã§ãã®ç´ æ´ãããã確èªãã¦ããã ããã°ã¨æãã¾ãã
以ä¸ã«æ¬æ¸ã®åæ¸ããå¼ç¨ãã¾ãã®ã§ãè³¼å ¥ã®éã®åèã«ãã¦ãã ããã
ãæ¬æ¸ã®åçãåè¡ããã¦ããã10å¹´ãçµéãã¾ãããçè ã«ã¨ã£ã¦ãåçã¯åãã¦æ¸ããæ¬ãããããå¦å¥³ä½ã§ãããèªåã®ç¥è¦ãæç« ãã©ã®ãããªåãåããæ¹ãããã®ãã¾ã£ããè¦å½ãã¤ããªãã¾ã¾æ¸ãã¦ãã¾ããã幸éãªãã¨ã«ãå¤ãã®èªè ã®æ¹ãã好æçã«åãã¨ãã¦ããã ããSQLã®è§£èª¬æ¸ã¨ãã¦ã¯ã¡ãã£ã¨ãããã³ã°ã»ã©ã¼ã¨ãªãã¾ãããããããæ¯æãããã ããã¨ã§ããã®ãã³ã®æ¹è¨ã«ã¤ãªãã£ãããã§ãã¾ãã¯äºåº¦ç®ã®æ©ä¼ãããã ãããã¨ã«æè¬ãããã¾ãã
ãæ¬æ¸ãé·ãæéèªã¾ãç¶ãã¦ããæ大ã®çç±ã¯ãRDBã¨SQLãé·å½ãä¿ã£ã¦ããããã§ããNoSQLãªã©ã®å°é ã¯ãããªããããRDBã¯ãã¾ã ã«å¤ãã®ã·ã¹ãã ã®æ°¸ç¶å±¤ã«ããããã¡ã¼ã¹ããã§ã¤ã¹ã§ãããSQLã¯ããããã©ãããããã®ç´è¦³çã§åªããã¤ã³ã¿ã¼ãã§ã¤ã¹ãæ¦å¨ã«ãè·æ¥ããã°ã©ããã¨ã³ã¸ãã¢ä»¥å¤ã®ã¨ã³ãã¦ã¼ã¶ã¼å±¤ã¸ãåºãããè¦ãã¦ãã¾ããã¨ã¯ãããSQLã10 å¹´ã¨ããæµãã®ä¸ã§å¤§ããªå¤è²ãéãã¾ããããã¤ã¦ã¯èããããªãã£ãã»ã©ã®å¤§éãã¼ã¿å¦çãè¡ãªããã¨ãæ±ããããããã«ãªããåææ¥åã¯ä¸é¨ã®å°é家ã ãã®ã¿ã¹ã¯ã§ã¯ãªããªã£ããã¨ã§ãSQLãµã¤ããã¾ãæ代ã®è¦è«ã«å¿ããããã«å¤§å¹ ãªæ©è½è¿½å ãè¡ãªããã¾ãããæ¬æ¸ã§ããããããææ°ååãåæ ããã¢ãã³ãªSQLããã°ã©ãã³ã°ã«å¯¾å¿ããã¹ãã¢ãããã¼ããè¡ãªãã¾ãããç¹ã«ãåçã§ã¯DBMSã®ãµãã¼ããä¸ååã ã£ããã大ããåãä¸ãããã¨ã®ã§ããªãã£ãã¦ã£ã³ãã¦é¢æ°ãå ¨é¢çã«æ¡ç¨ãã¦ãã¾ãã
ãåçãèªãã ãã¨ããªãã¨ããæ¹ã«åãã¦ãæ¬æ¸ã®æ¦è¦ã説æããã¨ãæ¬æ¸ã®ã³ã³ã»ããã¯ãä¸ç´SQLããã°ã©ãã³ã°å ¥éãã§ããå®åã§ã®SQLããã°ã©ãã³ã°ã®çµé¨ãåå¹´ãã1å¹´ãããããæ¹ãèªè ã«æ³å®ãã¦ãã¾ãããã£ã¨èº«ããµãããªãè¨ãæ¹ãããã¨ãJ.ã»ã«ã³ã®ãããã°ã©ãã®ããã®SQLããèªãã§ã¿ããã©æãåºãããã¨ãããããã®ã¬ãã«ã§ãï¼ãã¨ãã¨æ¬æ¸ã®åçã¯ãåæ¸ã®è§£èª¬æ¸ã¨ãã¦æ¸ããã¨ãããããã¾ãï¼ã
ãæ¬æ¸ã«ã¯ãCASEå¼ãã¦ã£ã³ãã¦é¢æ°ãå¤é¨çµåãç¸é¢ãµãã¯ã¨ãªãHAVINGå¥ãEXISTSè¿°èªãªã©SQLã®å¤ãã®éå ·ãç»å ´ãã¾ããããããã®åºæ¬çãªæ§æã¯ãããææ¡ãã¦ããã使ã£ããã¨ããããã¨ãããããã®ã¬ãã«ã§ããã°ååã«èªã¿é²ãããã¾ããæ¬æ¸ã®ç¬¬1é¨ã§ã¯ãããããSQL ã®éå ·ã1 ç« ã«ã¤ã1 ã¤åãä¸ãã¦ããããã®ä¾¿å©ãªä½¿ãæ¹ãããµã³ãã«ã±ã¼ã¹ãéãã¦å¦ãã§ããã¨ããã¹ã¿ã¤ã«ãæ¡ã£ã¦ãã¾ããçããããã²ãå®éã«æãåããã¦ãµã³ãã«ã³ã¼ããå®è¡ããªããå¦ç¿ãã¦ãã ãããåºæ¬çã«ã¯åããé çªã«èªãã§ããããã¨ãæ³å®ãã¦ãã¾ããããã§ã«ããç¥ã£ã¦ããå 容ã®ç« ã¯é£ã°ããããèå³ããç« ããèªãã§ããã¾ãã¾ããã
ãã¨ããã§æ¬æ¸ã«ã¯ãã1ã¤ãæ³å®ããèªè 層ãããã¾ãããã¡ãã¯ã¬ãã«ã«ãããããSQLã¨ã¯ä½ãªã®ãããç¥ãããã¨æã£ã¦ããæ¹ã ã対象ã¨ãã¦ãã¾ãããã®ãããªè¡¨ç¾ã¯å¥å¦ã«èãããããããã¾ããããå®éã®ã¨ãããSQLã¨ããã®ã¯ä¸æè°ãªè¨èªã§ããåç´è ã®ãã¡ã¯ãç°¡åãªãã¨ãç°¡åã«å®ç¾ã§ãã¦ä¾¿å©ãªè¨èªã ããããã«ããæããªãã£ãã®ããã¡ãã£ã¨æ·±ãç解ãããã¨ããã¨åççã«ã¯ç解ã§ããªãè¨èªä»æ§ã«çªãå½ãã£ãããå°ãè¤éãªãã¨ããããã¨ããã¨å¦ã«æ§æãé£ãããªã£ããã¨ãã£ããä¸å¯æè°ãªäºæ ã«ééãå§ãã¾ãããªããNULLã«ã¾ã¤ããSQLã®åä½ã¯ãããæ··ä¹±ãã¦ããã®ãï¼ããªããè¡éæ¯è¼ã«ç¸é¢ãµãã¯ã¨ãªã®ãããªé£ããæ§æãå¿ è¦ãªã®ãï¼ããªããæç¶ãåè¨èªã®ãããªã«ã¼ããå¤æ°ã¨ãã£ã便å©ãªéå ·ããªãã®ãï¼ããªãSQL ã§ã¯ããã¹ã¦ã®ãã表ç¾ãããã¨ãããã»ã©é£ããã®ãï¼â¦â¦
ãããããçåã¯ãããç¨åº¦ã®å²ãåããæã£ã¦ããããããã®ã ãã¨åãå ¥ãã¦ãã¾ãã°ãåé¿ãã¦é²ããã¨ãã§ãã¾ããå®éå¤ãã®ã¨ã³ã¸ãã¢ãããã°ã©ãã¯ãSQLã«å¯¾ãã¦ã¶ã¤ã¶ã¤æå¥ããããªãããããæ·±ã絡ãã¨é¢åãªãã¤ã ãé©å½ã«è·é¢ãä¿ã£ã¦ããã°ãããã便å©ãªä»äºä¸ã®ç¥ãåãããããã®ä»ãåãæ¹ããã¾ãããããããªãã«ã¯ãèªåã®ä½¿ã£ã¦ããéå ·ã®æãç«ã¡ãç¥ããããã¨æã人ãããã§ããããæ¬æ¸ã¯ããã®ãããªå¥½å¥å¿ãæã£ã¦ãã¾ã£ãèªè ã«å¯¾ãã¦ãSQLã®åçã¨ãªã£ã¦ããä»çµã¿ãããã®è¨èªãä½ã£ã人ã ãä½ãèãã¦ç¾å¨ã®ãããªå½¢ã«ããã®ããã¨ããããã¯ã°ã©ã¦ã³ããæãèµ·ããã¦ä¼ãããã¨ãç®æãã¦ãã¾ããæ¬æ¸ã®ç¬¬2é¨ã¯ããã®ãããªãSQLã¨ããè¨èªãã®ãã®ã«ã¾ã¤ããçåã«çãããã¨ãã¦ãã¾ãããã¡ããããã¹ã¦ã®çåã«çããã£ããã¨è¨ãåãèªä¿¡ã¯ããã¾ãããã1ã¤ã®è¨èªã®æ¬è³ªãç解ãã¦ãããã³ãã¯ç¤ºããã®ã§ã¯ãªããã¨æãã¾ãã
ãæ¬æ¸ããèªè ã®SQLããã°ã©ãã³ã°ã®ä¸éã«è²¢ç®ãããã¨ã¯ãã¡ãããããã°ã©ãã³ã°è¨èªã¨ããããã種ã®æåçç£ç©ã®æ·±å¥¥ãã®ããè¾¼ãé¢ç½ããæãã¦ãããããã¨ãç¥ã£ã¦ãã¾ãã
ãä¸å¯æè°ã«ãé¢ç½ããSQLã®ä¸çã¸ããããã
æ¢åã®æ¸ç±ã®æ¹è¨ãé¤ãã°ãããããæ¬æ¸ããç§ãRDBãSQLã«ã¤ãã¦æ¸ãæå¾ã®æ¬ã«ãªãã¨æãã¾ãï¼ãã®ãããã®äºæ ã«ã¤ãã¦ã¯æ¬¡åã¨ã³ããªã§è§¦ãã¾ãï¼ã
çããã楽ãã¿ãªããä¸éãããããªæ¬ã«ãªã£ã¦ããã°å¹¸ãã§ãã