skip to Main Content
column1 column2 
A       1
A       2
A       3
B       1
C       1
C       2
D       1

I want a query that prints

column1 column2 
B       1
D       1

Since B and D occur just once in the table.

I have tried queries like select column1 from table group by column1 having count(column1)=1 but this didn’t work.

2

Answers


  1. SELECT column1
    FROM TABLE
    GROUP BY column1
    HAVING count(column1)=1
    

    Hope this works in your case

    Login or Signup to reply.
  2. Maybe you need in this:

    SELECT t1.*
    FROM table t1
    JOIN (
        SELECT column1
        FROM table t2
        GROUP BY column1
        HAVING COUNT(column1)=1
        ) t3 USING (column1)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search