×ðÁú¿­Ê±¹ÙÍøµÇ¼

sqlÖÐinµÄÌæ»»º¯Êý

sql ÖÐ in ÔËËã·ûµÄÌæ»»º¯ÊýÓУºexists£º¼ì²é×ÓÅÌÎÊÊÇ·ñ·µ»ØÈκÎÐÐ ¡£any£º¼ì²éÁбíÖÐÊÇ·ñ±£´æÓë×ÓÅÌÎÊÆ¥ÅäµÄÖµ ¡£all£º¼ì²éÁбíÖÐËùÓÐÖµ¶¼Óë×ÓÅÌÎÊÆ¥Åä ¡£union all£º½«ÅÌÎÊЧ¹û×éºÏÔÚÒ»Æ𠡣ѡÔñÌæ»»º¯ÊýÈ¡¾öÓÚ±í½á¹¹ºÍ×ÓÅÌÎÊÖØ´óÐÔ ¡£

SQL ÖÐ IN µÄÌæ»»º¯Êý

IN ÔËËã·ûÓÃÓÚ¼ì²é¸ø¶¨µÄÖµÊÇ·ñÔÚÖ¸¶¨ÁбíÖÐ ¡£È»¶ø£¬ÔÚijЩÇéÐÎÏ£¬Ê¹Óà IN ÔËËã·û¿ÉÄÜЧÂʵÍÏ£¬ÓÈÆäÊÇÔÚÁбí°üÀ¨´ó×Úֵʱ ¡£ÎªÏàʶ¾öÕâ¸öÎÊÌ⣬SQL ÌṩÁ˼¸¸öÌæ»» IN ÔËËã·ûµÄº¯Êý£¬¿ÉÒÔÌá¸ßÐÔÄÜ ¡£

1. EXISTS

EXISTS ÔËËã·û¼ì²é¸ø¶¨µÄ×ÓÅÌÎÊÊÇ·ñ·µ»ØÈκÎÐÐ ¡£Ëü¿ÉÒÔÓÃÀ´È¡´ú IN ÔËËã·û£¬Óï·¨ÈçÏ£º

SELECT * FROM table1
WHERE EXISTS (SELECT * FROM table2 WHERE table2.id IN (1, 2, 3))

µÇ¼ºó¸´ÖÆ

2. ANY

ANY ÔËËã·û·µ»ØÒ»¸ö²¼¶ûÖµ£¬Ö¸Ê¾¸ø¶¨µÄÁбíÖÐÊÇ·ñ±£´æÓë×ÓÅÌÎÊ·µ»ØµÄÈκÎֵƥÅäµÄÖµ ¡£Ëü¿ÉÒÔÓÃÀ´È¡´ú IN ÔËËã·û£¬Óï·¨ÈçÏ£º

SELECT * FROM table1
WHERE table1.id = ANY (SELECT id FROM table2)

µÇ¼ºó¸´ÖÆ

3. ALL

ALL ÔËËã·û·µ»ØÒ»¸ö²¼¶ûÖµ£¬Ö¸Ê¾¸ø¶¨µÄÁбíÖÐËùÓÐÖµ¶¼Óë×ÓÅÌÎÊ·µ»ØµÄֵƥÅä ¡£Ëü¿ÉÒÔÓÃÀ´È¡´ú IN ÔËËã·û£¬Óï·¨ÈçÏ£º

SELECT * FROM table1
WHERE table1.id IN (SELECT id FROM table2)

µÇ¼ºó¸´ÖÆ

4. UNION ALL

UNION ALL ÔËËã·û¿ÉÒÔ½«Á½¸ö»ò¶à¸öÅÌÎʵÄЧ¹û×éºÏÔÚÒ»Æð ¡£Ëü¿ÉÒÔÓÃÀ´È¡´ú IN ÔËËã·û£¬Óï·¨ÈçÏ£º

SELECT * FROM table1
UNION ALL
SELECT * FROM table2
WHERE table2.id IN (1, 2, 3)

µÇ¼ºó¸´ÖÆ

Ñ¡ÔñºÏÊʵÄÌæ»»º¯Êý

Ñ¡Ôñ×îºÏÊʵÄÌæ»» IN ÔËËã·ûµÄº¯ÊýÈ¡¾öÓÚËùÅÌÎÊÊý¾ÝµÄ±í½á¹¹ºÍ×ÓÅÌÎʵÄÖØ´óÐÔ ¡£

EXISTS ×îÊʺϼì²é×ÓÅÌÎÊÊÇ·ñ·µ»ØÈκÎÐУ¬ÎÞÂÛ×ÓÅÌÎÊ·µ»Ø¼¸¶àÐÐ ¡£

ANY ×îÊʺϼì²é¸ø¶¨ÁбíÖÐÊÇ·ñ±£´æÓë×ÓÅÌÎÊÖзµ»ØµÄÈκÎֵƥÅäµÄÖµ ¡£

ALL ×îÊʺϼì²é¸ø¶¨ÁбíÖеÄËùÓÐÖµ¶¼Óë×ÓÅÌÎÊÖзµ»ØµÄֵƥÅä ¡£

UNION ALL ×îÊʺϽ«Á½¸ö»ò¶à¸öÅÌÎʵÄЧ¹û×éºÏÔÚÒ»Æð£¬ÆäÖÐÒ»¸öÅÌÎÊʹÓà IN ÔËËã·û ¡£

ÒÔÉϾÍÊÇsqlÖÐinµÄÌæ»»º¯ÊýµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼ ¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý ¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ