SQL question

You should get there though by finding proteins which have ANY peptide in the detectable mass range and then excluding them from all proteins.

So you want proteins with ALL it’s peptides below 100. Correct?

Darn. Needs to read “WHERE mass > 100” <- LARGER

SELECT DISTINCT ProteinID
FROM tbl_Peptides
WHERE ProteinID NOT IN(
SELECT ProteinID
FROM tbl_Peptides
WHERE mass > 100 )

Yup.

Should work now that I replaced < with >

My final version:

You can’t detect peptides below a minimum “mass” or above a maximum “mass”.

Number of proteins with no detectable peptides:
SELECT COUNT (DISTINCT ProteinID)
FROM tbl_Peptides
WHERE ProteinID NOT IN(
SELECT ProteinID
FROM tbl_Peptides
WHERE (m_over_z BETWEEN min AND max) OR (m_over_z_2 BETWEEN min AND max) )

Had no time to answer before you came out with your solution. Well, if you found a solution, it’s done. :slight_smile:

Sorry. Will endeavour to give more time at the next opportunity :wink:

But thanks to everyone. It helps to bounce your thoughts off other minds …

… and I’m always interested in optimised versions …

[quote=105502:@Markus Winter]My final version:

You can’t detect peptides below a minimum “mass” or above a maximum “mass”.

Number of proteins with no detectable peptides:
SELECT COUNT (DISTINCT ProteinID)
FROM tbl_Peptides
WHERE ProteinID NOT IN(
SELECT ProteinID
FROM tbl_Peptides
WHERE (m_over_z BETWEEN min AND max) OR (m_over_z_2 BETWEEN min AND max) )[/quote]
Distinct really isn’t necessary here. Rick’s original recommendation was using distinct in the subquery, but since you’re using IN, it won’t affect the results.