我想知道用于检查表的一个字段中的所有值是否存在于另一个表中的不同字段名称下的命令 [英] I wanted to know the command to check if all the values in one field of a table is present in another table under a different field name

查看:33
本文介绍了我想知道用于检查表的一个字段中的所有值是否存在于另一个表中的不同字段名称下的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张桌子.我想知道第一个表中的值是否存在于另一个具有不同字段名称的表中.

I have 2 tables. I want to find out whether the values present in the first table is there in another table with a different field name.

这是它的样子,

表1比尔号435291794325678735425676254677782435475845754748

Table1 BillNo 43529179 43256787 35425676 25467778 24354758 45754748

表2否113104808254265772685796792542135464252525232235263663

Table2 BNo 113104808 25426577 268579679 2542135464 252525232 235263663

我在 table1 中有 137 条记录需要对照 table2 进行检查.而不是使用以下命令一一执行,

I have 137 records in table1 that needs to be checked against table2. Instead of doing it one by one using the following command,

Select * from Table2 where BNo = '43529179';

Select * from Table2 where BNo = '43529179';

这仅给出了提到的值的结果.有没有办法检查单个查询中的所有值?

This gives the result for just the mentioned value. Is there a way to check for all the values in a single query?

谢谢!

推荐答案

加入表格,并检查有多少匹配的记录:

Join the tables, and check how many matching records there are:

select
  count(*) as Matches
from
  Table1 as t1
  inner join Table2 as t2 on t2.BNo = t1.BillNo

您也可以使用左连接来挑选表 1 中没有匹配表 2 记录的记录:

You can also use a left join to pick out the records in table 1 that has no matching record in table 2:

select
  t1.BillNo
from
  Table1 as t1
  left join Table2 as t2 on t2.BNo = t1.BillNo
where
  t2.BNo is null

这篇关于我想知道用于检查表的一个字段中的所有值是否存在于另一个表中的不同字段名称下的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆