{"id":27869,"date":"2024-11-24T15:59:07","date_gmt":"2024-11-24T07:59:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27869\/"},"modified":"2024-11-24T15:59:07","modified_gmt":"2024-11-24T07:59:07","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-exists-%e5%85%b3%e9%94%ae%e5%ad%97%e9%aa%8c%e8%af%81%e4%b8%a4%e4%b8%aa%e8%a1%a8%e4%b8%ad%e6%98%af%e5%90%a6%e5%ad%98%e5%9c%a8%e5%8c%b9%e9%85%8d%e5%80%bc%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27869\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 EXISTS \u5173\u952e\u5b57\u9a8c\u8bc1\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5339\u914d\u503c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173132532488462.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 EXISTS \u5173\u952e\u5b57\u9a8c\u8bc1\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5339\u914d\u503c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 EXISTS \u5173\u952e\u5b57\u9a8c\u8bc1\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5339\u914d\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 exists \u5173\u952e\u5b57\u9a8c\u8bc1\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5339\u914d\u503c<\/strong><\/p>\n<p>\u4e3a\u4e86\u67e5\u8be2\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5339\u914d\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 exists \u5173\u952e\u5b57\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>select *\nfrom table1\nwhere exists (\n    select *\n    from table2\n    where table1.column_name = table2.column_name\n);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6839\u636e\u4f60\u7684\u95ee\u9898\uff0c\u4f60\u5e0c\u671b\u68c0\u67e5\u4e3b\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5b50\u8868\u4e2d\u7684\u5185\u5bb9\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 exists \u6765\u9a8c\u8bc1\u8fd9\u4e00\u70b9\uff1a<\/p>\n<pre>SELECT *\nFROM (\n    SELECT pn_Code, serialNumber\n    FROM pnassertbasic_ruku pr\n    LEFT JOIN pnassertruku pu ON pr.parent_pnAssertRuku_id = pu.child_pnAssertRukuDetails_id\n    WHERE pn_Code IS NOT NULL AND serialNumber IS NOT NULL AND DATE(pr.create_time) = CURDATE() AND pr.warehouseEntryNumber &lt;&gt; 'WEd3791f0b'\n) AS temp1\nWHERE EXISTS (\n    SELECT *\n    FROM (\n        SELECT pn_Code, serialNumber\n        FROM pnassertbasic_ruku pr\n        LEFT JOIN pnassertruku pu ON pr.parent_pnAssertRuku_id = pu.child_pnAssertRukuDetails_id\n        WHERE pu.child_pnAssertRukuDetails_id IS NULL AND pr.warehouseEntryNumber = 'WEd3791f0b'\n    ) AS temp2\n    WHERE temp1.pn_Code = temp2.pn_Code AND temp1.serialNumber = temp2.serialNumber\n);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5df2\u66f4\u6b63\u4e86\u62fc\u5199\u9519\u8bef\u7684 select\uff0c\u5e76\u8c03\u6574\u4e86\u67e5\u8be2\u6761\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 EXISTS \u5173\u952e\u5b57\u9a8c\u8bc1\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5339\u914d\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 exists \u5173\u952e\u5b57\u9a8c\u8bc1\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5339\u914d\u503c \u4e3a\u4e86\u67e5\u8be2\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5339\u914d\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 exists \u5173\u952e\u5b57\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a select * from table1 where exists ( select * from table2 where table1.column_name = table2.column_name ); \u767b\u5f55\u540e\u590d\u5236 \u6839\u636e\u4f60\u7684\u95ee\u9898\uff0c\u4f60\u5e0c\u671b\u68c0\u67e5\u4e3b\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5b50\u8868\u4e2d\u7684\u5185\u5bb9\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 exists \u6765\u9a8c\u8bc1\u8fd9\u4e00\u70b9\uff1a SELECT * FROM ( SELECT pn_Code, serialNumber FROM pnassertbasic_ruku pr LEFT JOIN pnassertruku pu ON pr.parent_pnAssertRuku_id = pu.child_pnAssertRukuDetails_id WHERE pn_Code IS NOT NULL AND serialNumber IS NOT NULL AND [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27869","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27869"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27869\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}