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. Here is an example of what I would like to do: I have two tables, I'll call them TableA and 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. TableA:
Desired Result in TableA format:
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.
一个简单的连接就可以做到这一点。
select TableA.* from TableA inner join TableB on TableB.ID = TableA.IB
You can use 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.