[Solved] SQL BEGINNERS QUERY


This will give you all the subs where the Mem and Sub are not the same.

SELECT SUB
    FROM TABLE
    WHERE MEM <> SUB

This will give you a distinct list of Sub’s that, at one point or another, do not have a matching MEM.

SELECT DISTINCT SUB
    FROM TABLE
    WHERE MEM <> SUB

EDIT:

I WANT TO FIND OUT ALL SUB THATHAS ONLY ONE MEM

This is a really simple SQL query. You’ll probably learn it better if you did some research.
Regardless, here is what you need:

SELECT SUB
  , COUNT(MEM) AS CountOfMem
     FROM TABLE
     GROUP BY SUB
     HAVING COUNT(MEM) = 1

If this is it, make sure to mark it as answered.

1

solved SQL BEGINNERS QUERY