select a.artno, a.name
from Art a
inner join store s on a.Artno <> s.Artno`
Running this query took me more than 1 min producing more 899K rows while was supposed to bring out 7.9K results.
select artno
from art
except
(select artno from store)
This line of code provides me with 7.9K rows which is true for me.
The first codes seems to be working code but takes a hack of a time and produces a large result set. Wondering why?
It’s generally NOT a good idea to use a
<>operator with an INNER JOIN unless you really know that you want a lot of records. In other words, the JOIN is a great tool for inclusion, not exclusion.When you do an INNER JOIN using a
<>operator (especially on the keys), the query brings back every combination ofartandstorerecords except where theArtnokeys match.So, if your have 4
artrecords and 5storerecords, only one of which had a matchingArtNovalue, you would end up with 4 x 5 – 1 = 19 records.The second query simply displays all
artrecords that aren’t in any store.