mysqlÖÐall anyµÄÓ÷¨
mysql ÖÐµÄ all ºÍ any ÔËËã·ûÓÃÓÚ½ÏÁ¿ÜöÝÍÊÇ·ñÖª×ãÌض¨Ìõ¼þ¡£all ¼ì²éËùÓÐÔªËØÊÇ·ñ¶¼Öª×㣬¶ø any Ö»ÐèÒªÓÐÒ»¸öÔªËØÖª×ã¼´¿É¡£
MySQL ÖÐµÄ ALL ºÍ ANY
ALL ºÍ ANY ÊÇ MySQL ÖеÄÜöÝÍÔËËã·û£¬ÓÃÓÚ½ÏÁ¿Á½¸ö»ò¶à¸öÜöÝÍÊÇ·ñÖª×ãÌض¨Ìõ¼þ¡£
ALL
ALL ÔËËã·û¼ì²é¸ø¶¨ÜöÝÍÖеÄËùÓÐÔªËØÊÇ·ñ¶¼Öª×ã×ÓÅÌÎÊ·µ»ØµÄЧ¹û¡£Óï·¨ÈçÏ£º
SELECT * FROM table1 WHERE condition ALL (SELECT condition FROM table2);
µÇ¼ºó¸´ÖÆ
ÈôÊÇ×ÓÅÌÎʹØÓÚ table1 ÖеÄÿÌõ¼Í¼¶¼·µ»ØÕ棬Ôò·µ»Ø¸Ã¼Í¼¡£»»¾ä»°Ëµ£¬ÈôÊÇËùÓÐÔªËض¼Öª×ã×ÓÅÌÎÊÌõ¼þ£¬Ôò·µ»Ø true¡£
Àý£º
SELECT * FROM students WHERE city ALL (SELECT city FROM states WHERE country = 'USA');
µÇ¼ºó¸´ÖÆ
Õ⽫·µ»ØËùÓÐÆÜÉíÔÚÃÀ¹úµÄËùÓÐÖݵÄѧÉú¼Í¼¡£
ANY
ANY ÔËËã·û¼ì²é¸ø¶¨ÜöÝÍÖеÄÈκÎÔªËØÊÇ·ñÖª×ã×ÓÅÌÎÊ·µ»ØµÄЧ¹û¡£Óï·¨ÈçÏ£º
SELECT * FROM table1 WHERE condition ANY (SELECT condition FROM table2);
µÇ¼ºó¸´ÖÆ
ÈôÊÇ×ÓÅÌÎÊÖÁÉÙ¹ØÓÚ table1 ÖеÄÒ»Ìõ¼Í¼·µ»ØÕ棬Ôò·µ»Ø¸Ã¼Í¼¡£»»¾ä»°Ëµ£¬ÈôÊÇÈκÎÔªËØÖª×ã×ÓÅÌÎÊÌõ¼þ£¬Ôò·µ»Ø true¡£
Àý£º
SELECT * FROM employees WHERE salary ANY (SELECT salary FROM managers WHERE department = 'Sales');
µÇ¼ºó¸´ÖÆ
Õ⽫·µ»ØËùÓÐÈËΪÓëÈκÎÏúÊÛ²¿·Ö˾ÀíÈËΪÏàͬµÄÔ±¹¤¼Í¼¡£
ÒÔÉϾÍÊÇmysqlÖÐall anyµÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡