简体   繁体   English

显示具有来自不同表的匹配数据的 SQL 表记录

[英]Display SQL Table records that have matching data from different table

I am very new to SQL, and I am trying to filter a set of records from one table based on matching columns from another table.我对 SQL 很陌生,我试图根据另一个表中的匹配列过滤一个表中的一组记录。 Here is an example of what I would like to do: I have two tables, I'll call them TableA and TableB.这是我想要做的一个例子:我有两个表,我将它们称为 TableA 和 TableB。 I have already applied a search on both Tables to filter their separate results down, but I want to filter TableA based on matching records from TableB.我已经在两个表上应用了搜索来过滤它们单独的结果,但我想根据来自 TableB 的匹配记录过滤 TableA。 TableA:表A: 在此处输入图片说明

TableB:表B: 在此处输入图片说明

Desired Result in TableA format: TableA 格式的期望结果: 在此处输入图片说明

TableB and TableA have matching ID columns, and I only want to display the records in TableA if the records also appear in TableB, but I need them to appear in TableA format. TableB 和 TableA 有匹配的 ID 列,如果记录也出现在 TableB 中,我只想显示 TableA 中的记录,但我需要它们以 TableA 格式出现。

一个简单的连接就可以做到这一点。

select TableA.* from TableA inner join TableB on TableB.ID = TableA.IB

You can use exists :您可以使用exists

select a.*
from a
where exists (select 1 from b where a.id = b.id);

你需要做类似的事情

Select a.id, a.first_name, a.last_name, a.birthday, a.ssn from TableA a, Table b where a.id=b.id

暂无
暂无

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

相关问题 想要显示表中不匹配的记录 - want to display not matching records from table 如何使用 SQL 从没有任何 id 列的两个不同表中找到完全匹配的记录 - How can I find exact matching records from two different table which doesn't have any id column using SQL SQL仅查找表中没有匹配记录的数据 - SQL to find only data in a table with no matching records SQL查询以获取来自Table1和Table2的匹配记录,并使用自定义列显示1/0(如果存在数据) - SQL query to get matching records from Table1 and Table2 with a custom column showing 1/0 if data is present 从3个不同的表中查询数据-检查表是否具有匹配的记录(如果没有),然后显示它们 - Querying data from 3 different tables based -checking if tables have matching records if not then display them SQL在不同的行中显示来自同一表的不同数据 - SQL display different data from the same table in different rows 从sql表中计数记录并在文本框中显示它 - count records from sql table and display it on textbox 来自两个不同表的生效日期,匹配特定日期的记录 - Effective Dates from Two Different Table, Matching Records as of a Certain Date SQL查询-从一个表中选择全部,在另一个表中匹配记录 - SQL Query - select all from one table with matching records in another SQL JOIN:从另一个具有匹配ID的表中选择记录 - SQL JOIN: Select Records from Another Table With Matching IDs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM