Akki
Akki

Reputation: 9

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.

Upvotes: 0

Views: 71

Answers (3)

Dhara Bhalala
Dhara Bhalala

Reputation: 224

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)

Upvotes: 2

Iswanto San
Iswanto San

Reputation: 18569

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)

Upvotes: 0

Mudassir Hasan
Mudassir Hasan

Reputation: 28751

Select id from xyz 
where id not in ( Select abc_id from abc)

See more details about NOT IN() comparison function here

Upvotes: 1

Related Questions