• <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?

        时间:2023-10-08
        <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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:多个“标签"的Mysql join查询(多对多关系)匹配所有标签? 下一篇:T-SQL 子查询 Max(Date) 和 Joins

                  相关文章

                • <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>