07lodgeT
07lodgeT

Reputation: 108

MySQL Comparison in two tables

I have two tables (products and span_products) with many columns each but each has one called part_no, The should have the same part numbers in both tables but in a different order,

whats the easiest way to show which rows aren't in the span_products table

Upvotes: 0

Views: 34

Answers (2)

jarlh
jarlh

Reputation: 44766

Or use a NOT EXISTS:

select *
from products p
where NOT EXISTS (select 1 from span_products s where s.part_no = p.part_no)

I.e. select all products that aren't found in span_products.

Upvotes: 0

juergen d
juergen d

Reputation: 204766

Use a left join

select p.*
from products p
left join span_products s on s.part_no = p.part_no
where s.part_no is null

See this explanation of joins

Upvotes: 1

Related Questions