• <small id='ukYZC'></small><noframes id='ukYZC'>

      • <bdo id='ukYZC'></bdo><ul id='ukYZC'></ul>

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

      <tfoot id='ukYZC'></tfoot>
      1. <legend id='ukYZC'><style id='ukYZC'><dir id='ukYZC'><q id='ukYZC'></q></dir></style></legend>
      2. 如何在sql中使用like和join?

        how to use a like with a join in sql?(如何在sql中使用like和join?)
        <legend id='k8LtX'><style id='k8LtX'><dir id='k8LtX'><q id='k8LtX'></q></dir></style></legend>

        1. <small id='k8LtX'></small><noframes id='k8LtX'>

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

                  <tbody id='k8LtX'></tbody>
                  <bdo id='k8LtX'></bdo><ul id='k8LtX'></ul>
                  本文介绍了如何在sql中使用like和join?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 2 个表,比如表 A 和表 B,我想执行连接,但匹配条件必须是 A 中的列类似于"B 中的列,这意味着任何东西都可以在之前或之后出现B中的列:

                  I have 2 tables, say table A and table B and I want to perform a join, but the matching condition has to be where a column from A 'is like' a column from B meaning that anything can come before or after the column in B:

                  例如:如果 A 中的列是 'foo'.如果 B 中的列是:'fooblah'、'somethingfooblah' 或只是 'foo',则连接将匹配.我知道如何在标准的 like 语句中使用通配符,但在进行连接时很困惑.这有意义吗?谢谢.

                  for example: if the column in A is 'foo'. Then the join would match if column in B is either: 'fooblah', 'somethingfooblah', or just 'foo'. I know how to use the wildcards in a standard like statement, but am confused when doing a join. Does this make sense? Thanks.

                  推荐答案

                  Using INSTR:

                  SELECT *
                    FROM TABLE a
                    JOIN TABLE b ON INSTR(b.column, a.column) > 0
                  

                  使用喜欢:

                  SELECT *
                    FROM TABLE a
                    JOIN TABLE b ON b.column LIKE '%'+ a.column +'%'
                  

                  将 LIKE 与 CONCAT 一起使用:

                  Using LIKE, with CONCAT:

                  SELECT *
                    FROM TABLE a
                    JOIN TABLE b ON b.column LIKE CONCAT('%', a.column ,'%')
                  

                  请注意,在所有选项中,您可能希望在比较之前将列值驱动为大写,以确保您获得匹配项而无需担心区分大小写:

                  Mind that in all options, you'll probably want to drive the column values to uppercase BEFORE comparing to ensure you are getting matches without concern for case sensitivity:

                  SELECT *
                    FROM (SELECT UPPER(a.column) 'ua'
                           TABLE a) a
                    JOIN (SELECT UPPER(b.column) 'ub'
                           TABLE b) b ON INSTR(b.ub, a.ua) > 0
                  

                  最有效的最终取决于EXPLAIN计划输出.

                  The most efficient will depend ultimately on the EXPLAIN plan output.

                  JOIN 子句与编写 WHERE 子句相同.JOIN 语法也被称为 ANSI JOIN,因为它们是标准化的.非 ANSI JOIN 看起来像:

                  JOIN clauses are identical to writing WHERE clauses. The JOIN syntax is also referred to as ANSI JOINs because they were standardized. Non-ANSI JOINs look like:

                  SELECT *
                    FROM TABLE a,
                         TABLE b
                   WHERE INSTR(b.column, a.column) > 0
                  

                  我不会为非 ANSI LEFT JOIN 示例而烦恼.ANSI JOIN 语法的好处在于它将表连接在一起的内容与 WHERE 子句中实际发生的内容分开.

                  I'm not going to bother with a Non-ANSI LEFT JOIN example. The benefit of the ANSI JOIN syntax is that it separates what is joining tables together from what is actually happening in the WHERE clause.

                  这篇关于如何在sql中使用like和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='LamVF'></tbody>

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

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

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