<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 检查相关行不存在的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                    <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'>