简体   繁体   中英

Finding records in TableA that don't exist in Table B in MySql

I have a multi-million Table A which includes Field1

I have another similar Table B

I have done various queries prior on Table A/Field 1

I'd like to try to isolate those Field1s in TableB I am going to need to run similar queries on

So I'd like to basically extract a list of Field1 from TableB where that Field1 does NOT already exist in TableA so I can start to process those records.

I think the fastest way would be:

SELECT b.*, a.id 
FROM b
LEFT JOIN a
ON b.field1 = a.field1
WHERE a.id IS NULL;
select field1 
from tableB 
where not exists (select * from tableA where tableB.field1 = tableA.field1)

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.

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