mysqlÖÐinµÄ×÷ÓÃ
mysql ÖÐµÄ in ²Ù×÷·ûÓÃÓÚ¼ì²éÒ»¸öÁеÄÖµÊÇ·ñÔÚÖ¸¶¨ÖµÁбíÖУ¬Ê¹Äú¿ÉÒÔÇáËɲéÕÒ°üÀ¨Ìض¨ÖµµÄ¼Í¼¡£ÆäÓ﷨Ϊ£ºselect column_name from table_name where column_name in (value1, value2, …, valuen)¡£Ê¹Óà in ²Ù×÷·ûʱ£¬mysql »áÖðÒ»¼ì²éÁÐÖµÊÇ·ñÓëÁбíÖеÄÈκÎֵƥÅ䣬ÈôÊÇÆ¥Å䣬¸Ã¼Í¼½«±»ÄÉÈëЧ¹û¼¯ÖС£
MySQL ÖÐ IN µÄ×÷ÓÃ
IN ²Ù×÷·ûÔÚ MySQL ÖÐÓÃÓÚ¼ì²éÒ»¸öÁеÄÖµÊÇ·ñÔÚÖ¸¶¨ÖµµÄÁбíÖС£µ±ÄúÐèÒª²éÕÒ°üÀ¨¶à¸öÌض¨ÖµµÄ¼Í¼ʱ£¬IN ²Ù×÷·ûºÜÊÇÓÐÓá£
Óï·¨
SELECT column_name FROM table_name WHERE column_name IN (value1, value2, ..., valueN);
µÇ¼ºó¸´ÖÆ
ÆäÖУº
column_name ÊÇÄúÒª¼ì²éµÄÁеÄÃû³Æ¡£
value1, value2, …, valueN ÊÇÄúÕýÔÚ²éÕÒµÄÌض¨ÖµÁÐ±í¡£
Ó÷¨
ʹÓà IN ²Ù×÷·û¾ÙÐÐÅÌÎÊʱ£¬MySQL »áÖðÒ»¼ì²éÁÐÖµÊÇ·ñÓëÁбíÖеÄÈκÎֵƥÅä¡£ÈôÊÇÁÐֵƥÅäÁбíÖеÄÈκÎÖµ£¬Ôò¸Ã¼Í¼½«°üÀ¨ÔÚЧ¹û¼¯ÖС£
ʾÀý
¼ÙÉèÄúÓÐÒ»¸öÃûΪ students µÄ±í£¬ÆäÖаüÀ¨ student_id¡¢name ºÍ age ÁС£ÄúÒª²éÕÒÄêËêΪ 20¡¢21 »ò 22 µÄѧÉú£¬¿ÉÒÔʹÓÃÒÔÏÂÅÌÎÊ£º
SELECT name FROM students WHERE age IN (20, 21, 22);
µÇ¼ºó¸´ÖÆ
¸ÃÅÌÎʽ«·µ»ØÄêËêΪ 20¡¢21 »ò 22 µÄËùÓÐѧÉúµÄÐÕÃû¡£
×¢ÖØÊÂÏî
IN ²Ù×÷·û¿ÉÒÔÓë×Ö·û´®¡¢Êý×ÖºÍÈÕÆÚÖµÒ»ÆðʹÓá£
Äú¿ÉÒÔÖ¸¶¨í§ÒâÊýÄ¿µÄÖµÁÐ±í¡£
IN ²Ù×÷·ûÓë NOT IN ²Ù×÷·ûÀàËÆ£¬ºóÕßÓÃÓÚ²éÕÒ²»°üö¾Ù±íÖÐÈκÎÖµµÄ¼Í¼¡£
ÒÔÉϾÍÊÇmysqlÖÐinµÄ×÷ÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡