EXISTSç¨äºæ£æ¥åæ¥è¯¢æ¯å¦è³å°ä¼è¿åä¸è¡æ°æ®ï¼è¯¥åæ¥è¯¢å®é
ä¸å¹¶ä¸è¿åä»»ä½æ°æ®ï¼èæ¯è¿åå¼TrueæFalse
EXISTS æå®ä¸ä¸ªåæ¥è¯¢ï¼æ£æµ è¡ çåå¨ã
è¯æ³ï¼ EXISTS subquery
åæ°ï¼ subquery æ¯ä¸ä¸ªåéç SELECT è¯å¥ (ä¸å
许æ COMPUTE åå¥å INTO å
³é®å)ã
ç»æç±»åï¼ Boolean å¦æåæ¥è¯¢å
å«è¡ï¼åè¿å TRUE ï¼å¦åè¿å FLASE ã
ä¾è¡¨Aï¼TableIn ä¾è¡¨Bï¼TableEx
ï¼ä¸ï¼. å¨åæ¥è¯¢ä¸ä½¿ç¨ NULL ä»ç¶è¿åç»æé
select * from TableIn where exists(select null)
çåäºï¼ select * from TableIn
ï¼äºï¼. æ¯è¾ä½¿ç¨ EXISTS å IN çæ¥è¯¢ã注æ两个æ¥è¯¢è¿åç¸åçç»æã
select * from TableIn where exists(select BID from TableEx where BNAME=TableIn.ANAME)
select * from TableIn where ANAME in(select BNAME from TableEx)
ï¼ä¸ï¼. æ¯è¾ä½¿ç¨ EXISTS å = ANY çæ¥è¯¢ã注æ两个æ¥è¯¢è¿åç¸åçç»æã
select * from TableIn where exists(select BID from TableEx where BNAME=TableIn.ANAME)
select * from TableIn where ANAME=ANY(select BNAME from TableEx)
NOT EXISTS çä½ç¨ä¸ EXISTS æ£å¥½ç¸åãå¦æåæ¥è¯¢æ²¡æè¿åè¡ï¼åæ»¡è¶³äº NOT EXISTS ä¸ç WHERE åå¥ã
ç»è®ºï¼
EXISTS(å
æ¬ NOT EXISTS )åå¥çè¿åå¼æ¯ä¸ä¸ªBOOLå¼ã EXISTSå
é¨æä¸ä¸ªåæ¥è¯¢è¯å¥(SELECT ... FROM...)ï¼ æå°å
¶ç§°ä¸ºEXISTçå
æ¥è¯¢è¯å¥ãå
¶å
æ¥è¯¢è¯å¥è¿åä¸ä¸ªç»æéã EXISTSåå¥æ ¹æ®å
¶å
æ¥è¯¢è¯å¥çç»æé空æè
é空ï¼è¿åä¸ä¸ªå¸å°å¼ã
温馨提示:答案为网友推荐,仅供参考