inÔÚsqlÖеÄÓ÷¨
sql ÖÐ in ²Ù×÷·ûÓÃÓÚ¼ì²éÒ»¸öÖµÊÇ·ñ°üÀ¨ÔÚÖ¸¶¨µÄÒ»×éÖµÖУ¬ÆäÓ﷨Ϊ£ºselect column_name from table_name where column_name in (value1, value2, …, valuen)¡£Ëü¿ÉÒÔÓÃÓÚ¼ì²éµ¥¸öÖµ£¨ÀýÈç select customer_name from customers where customer_id in (10)£©»ò¶à¸öÖµ£¨ÀýÈç select customer_name from customers where c
SQL ÖÐ IN ²Ù×÷·û
×÷Óãº
IN ²Ù×÷·ûÓÃÓÚ¼ì²éÒ»¸öÖµÊÇ·ñ°üÀ¨ÔÚÖ¸¶¨µÄÒ»×éÖµÖС£
Óï·¨£º
SELECT column_name FROM table_name WHERE column_name IN (value1, value2, ..., valueN);
µÇ¼ºó¸´ÖÆ
²ÎÊý£º
column_name£ºÒª¼ì²éµÄÖµËùÔÚµÄÁÐÃû
value1, value2, …, valueN£ºÒª¼ì²éµÄÖµµÄÁÐ±í£¬¿ÉÒÔÊdz£Á¿¡¢×ÓÅÌÎÊ»ò´ÓÆäËû±íÖÐÑ¡È¡µÄÖµ
ÔõÑùʹÓãº
ʹÓà IN ²Ù×÷·û½«Ò»×éÖµÀ¨ÔÚÔ²À¨ºÅÖС£
½« IN ²Ù×÷·û°²ÅÅÔÚ WHERE ×Ó¾äÖУ¬²¢½ô¸úÒª¼ì²éµÄÁÐÃû¡£
ÔÚ IN ²Ù×÷·ûºóÃæÁгöÒª¼ì²éµÄÖµ¡£
ʾÀý£º
SELECT customer_name FROM customers WHERE customer_id IN (10, 15, 20);
µÇ¼ºó¸´ÖÆ
Õâ¸öÅÌÎʽ«·µ»Ø°üÀ¨¿Í»§ ID Ϊ 10¡¢15 »ò 20 µÄËùÓпͻ§µÄÐÕÃû¡£
×¢ÖØÊÂÏ
IN ²Ù×÷·û¿ÉÒÔ¼ì²é¿ÕÖµ£¬¿ÉÊÇËü½«·µ»Ø NULL¡£
IN ²Ù×÷·ûµÄÐÔÄÜ»áÊܵ½ÖµÁÐ±í³¤¶ÈµÄÓ°Ïì¡£¹ØÓڽϳ¤µÄÁÐ±í£¬¿ÉÒÔʹÓà EXISTS »ò NOT IN ²Ù×÷·ûÌá¸ßÐÔÄÜ¡£
ÒÔÉϾÍÊÇinÔÚsqlÖеÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡