<i id='hfmGM'><tr id='hfmGM'><dt id='hfmGM'><q id='hfmGM'><span id='hfmGM'><b id='hfmGM'><form id='hfmGM'><ins id='hfmGM'></ins><ul id='hfmGM'></ul><sub id='hfmGM'></sub></form><legend id='hfmGM'></legend><bdo id='hfmGM'><pre id='hfmGM'><center id='hfmGM'></center></pre></bdo></b><th id='hfmGM'></th></span></q></dt></tr></i><div id='hfmGM'><tfoot id='hfmGM'></tfoot><dl id='hfmGM'><fieldset id='hfmGM'></fieldset></dl></div>
  • <tfoot id='hfmGM'></tfoot>

    1. <legend id='hfmGM'><style id='hfmGM'><dir id='hfmGM'><q id='hfmGM'></q></dir></style></legend>

      <small id='hfmGM'></small><noframes id='hfmGM'>

        <bdo id='hfmGM'></bdo><ul id='hfmGM'></ul>

      1. 使用 LEFT OUTER JOIN 检查相关行不存在的最佳方法是什么

        What#39;s the best way to use LEFT OUTER JOIN to check for non-existence of related rows(使用 LEFT OUTER JOIN 检查相关行不存在的最佳方法是什么)

        <legend id='nUAxN'><style id='nUAxN'><dir id='nUAxN'><q id='nUAxN'></q></dir></style></legend>

      2. <i id='nUAxN'><tr id='nUAxN'><dt id='nUAxN'><q id='nUAxN'><span id='nUAxN'><b id='nUAxN'><form id='nUAxN'><ins id='nUAxN'></ins><ul id='nUAxN'></ul><sub id='nUAxN'></sub></form><legend id='nUAxN'></legend><bdo id='nUAxN'><pre id='nUAxN'><center id='nUAxN'></center></pre></bdo></b><th id='nUAxN'></th></span></q></dt></tr></i><div id='nUAxN'><tfoot id='nUAxN'></tfoot><dl id='nUAxN'><fieldset id='nUAxN'></fieldset></dl></div>
                  <bdo id='nUAxN'></bdo><ul id='nUAxN'></ul>
                • <small id='nUAxN'></small><noframes id='nUAxN'>

                  <tfoot id='nUAxN'></tfoot>
                    <tbody id='nUAxN'></tbody>
                  本文介绍了使用 LEFT OUTER JOIN 检查相关行不存在的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 MySQL 5.x 我想有效地从表 X 中选择表 Y 中没有相关行满足某些条件的所有行,例如

                  Using MySQL 5.x I want to efficiently select all rows from table X where there is no related row in table Y satisfying some condition, e.g.

                  给我 X 中所有与 foo = bar 相关的 Y 不存在的记录

                  Give me all records in X where a related Y with foo = bar does NOT exist

                  SELECT count(id) FROM X
                  LEFT OUTER JOIN Y ON y.X_id = X.id AND y.foo = 'bar'
                  WHERE y....?
                  

                  据我所知,左外连接保证为左(第一个)表中的每一行生成一行——在本例中为 X——无论是否在连接表中找到了令人满意的行.我想要做的就是只选择那些没有找到行的行.

                  As I understand it, a left outer join is guaranteed to produce a row for each row in the left (first) table -- X in this case -- whether or not a satisfying row in the joined table was found. What I want to do is then select only those rows where no row was found.

                  在我看来,如果没有匹配的记录,y.X_id 应该是 NULL,但是这个测试似乎不起作用.y.X_id = 0 或 !y.X_id 也不是.

                  It seems to me that y.X_id should be NULL if there is no matching record, but this test doesn't seem to work. Nor does y.X_id = 0 or !y.X_id.

                  编辑:更正了多个回复指出的转录错误(ON 不是 AS).修正语法错误.

                  Edits: corrected transcription error (ON not AS) which was pointed out by several responses. Fixed grammatical error.

                  推荐答案

                  SELECT count(id) FROM X 
                  LEFT OUTER JOIN Y ON (y.X_id = X.id AND y.foo = 'bar')
                  WHERE y.X_id is null
                  

                  你已经接近了.

                  首先照常进行连接,然后选择 Y 中 not null 行实际上是 null 的所有行,因此您确定存在不匹配"" 而不仅仅是 Y 中的 null 值.

                  First do the join as normal, then select all rows for which a not null row in Y is in fact null, so you are sure there's a "no match" and not just a null value in Y.

                  还要注意您在查询中的拼写错误(已更正):

                  Also note the typo (since corrected) you made in the query:

                  LEFT OUTER JOIN Y AS
                  -- should be
                  LEFT OUTER JOIN Y ON
                  -- This however is allowed
                  LEFT OUTER JOIN table2 as Y ON ....
                  

                  这篇关于使用 LEFT OUTER JOIN 检查相关行不存在的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                    <tbody id='Td8eN'></tbody>
                    <bdo id='Td8eN'></bdo><ul id='Td8eN'></ul>
                    <tfoot id='Td8eN'></tfoot>

                    <legend id='Td8eN'><style id='Td8eN'><dir id='Td8eN'><q id='Td8eN'></q></dir></style></legend>
                    <i id='Td8eN'><tr id='Td8eN'><dt id='Td8eN'><q id='Td8eN'><span id='Td8eN'><b id='Td8eN'><form id='Td8eN'><ins id='Td8eN'></ins><ul id='Td8eN'></ul><sub id='Td8eN'></sub></form><legend id='Td8eN'></legend><bdo id='Td8eN'><pre id='Td8eN'><center id='Td8eN'></center></pre></bdo></b><th id='Td8eN'></th></span></q></dt></tr></i><div id='Td8eN'><tfoot id='Td8eN'></tfoot><dl id='Td8eN'><fieldset id='Td8eN'></fieldset></dl></div>
                  • <small id='Td8eN'></small><noframes id='Td8eN'>