0

I have the following table:

+-----------------------------+-----------+
| keyword                     | data_type |
+-----------------------------+-----------+
| red                         | ctr       |
| blue                        | ctr       |
| purple                      | ctr       |
| orange                      | ctr       |
| red                         | var       |
| blue                        | var       |
| black                       | var       |
| yellow                      | var       |
+-----------------------------+-----------+

I'd like to be able to select only those which are distinct by data_type.

For example: If I checked by data_type: var, 'black' and 'yellow' would be returned.

If I checked by data_type: ctr, 'purple' and 'orange' would be returned.

I'd normally provide an example query of what I've done, thus far, but I don't know where to start with this one - help is much appreciated.

  • please, add the desired result – McNets May 26 '17 at 12:54
  • I have? Happy to update if another format is needed? – Adders May 26 '17 at 12:56
2

Pretty straight forward:

SELECT * FROM table
WHERE data_type = 'var'
AND keyword NOT IN (SELECT keyword FROM table WHERE data_type <> 'var');
| improve this answer | |
  • Thank you, that's perfect - seems so straight forward now. I'm going to write it out a few times to get it in my head – Adders May 26 '17 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.