# Miscellaneous > SQL Scripts >  problem with a self join...

## niko

I'm a newbie in sql queries and don't know how to solve the following question:

are there subclasses in which ALL chemicals have a MolMass < 400 ?

relation given (prim. key: ChemID):

Chemicals (ChemID, Name, MolMass, SubclassID)


 Many thanks

----------


## andi_g69

SELECT DISTINCT SubClassID
FROM Chemicals c
WHERE SubClassID NOT IN (
SELECT SubClassID
FROM Chemicals s
WHERE MolMass >= 400
GROUP BY SubClassID)

----------


## niko

many thanks for your help ! :Big Grin:

----------

