简体   繁体   English

根据条件比较不同表中的两列

[英]Comparing two columns in different tables based on condition

I have two tables as shown 我有两个表,如图所示

Table1: 表格1:

| ldt    | swpn   | nomenclature | planned | combined     |

Table2: 表2:

| lmt | name | combination |

I have to achieve: 我必须实现:

  1. Check if the value in column "combination" exists in the column "combined". 检查“组合”列中是否存在“组合”列中的值。

  2. If it exists printout the corresponding | lmt | name | combination | 如果存在,则输出相应的| lmt | name | combination | | lmt | name | combination |

Use an INNER JOIN, its used to get results from both tables on the LEFT and RIGHT of the JOIN 使用INNER JOIN,它用于从JOIN的LEFT和RIGHT的两个表中获取结果

SELECT t2.lmt, t2.name, t2.combination
FROM
    t1
    INNER JOIN t2 ON t1.combined=t2.combination
SELECT Table2.lmt, Table2.name, Table2.combination FROM Table1, Table2 WHERE Table2.combination=Table1.combined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM