简体   繁体   中英

how to get unique record from table in mysql

I am having two tables called abc and xyz . The table xyz contains column id and xyz contains abc_id .

I want to find record present in first table but not present in second table. How can I do this.

If you want to fetch records from abc table which not in xyz table;

SELECT abc_id FROM abc 
WHERE abc_id NOT IN (SELECT id from xyz)
Select id from xyz 
where id not in ( Select abc_id from abc)

See more details about NOT IN() comparison function here

You can use IN as @m.hasan answer or use EXISTS

> Select id from xyz  where not exists ( Select abc_id from abc where
> abc_id = xyz.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.

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