malteser
malteser

Reputation: 485

SQL - Removing other entries

So I have this table (table1):

enter image description here

I need to know all the 'num' who dont know HTML

I tried - SELECT num FROM table1 WHERE package <> HTML

The problem is, for example, that NUM 2 knows Excel aswell, so he still shows up in the result...

Any ideas?

Upvotes: 1

Views: 51

Answers (3)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44874

Here is another way of doing it using not exists

select 
distinct num from table_name t1
where not exists
(
  select 1 from table_name t2
  where t2.package = 'HTML'
  and t1.num = t2.num
)

Upvotes: 3

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33391

Try this:

SELECT DISTINCT num
FROM table1
WHERE num NOT IN (SELECT num FROM table1 WHERE package = 'HTML')

Upvotes: 3

Kinexus
Kinexus

Reputation: 12904

SELECT DISTINCT num FROM table1 
WHERE
(num NOT IN (SELECT num FROM table1 WHERE package = 'HTML'))

I don't have access to a MySQL box at this moment, but that should work.

Upvotes: 3

Related Questions