Q:

SQl query to get unique records

I have the below data:
pdtid  version  col1 col2 col3

1        1       0     0   0
1        2       0     0   0
1        3       0     0   0 
2        1       0     0   0
2        2       1     1   0
3        1       0     0   0
4        1       0     0   0
4        2       0     1   0

How do I write a query that returns pdtid 1 and 3 when it meets the condition col1 = 0, col2 = 0 and col3 = 0?
Edit: pdtid should only be returned if all records with a pdtid meet the criterium col1=0 and col2=0 and col3=0
In this example, the result should return pdtid 1 and 3, but not 2, because 2 contains a record which does not meet the criteria.

A:

Isn't this as simple as writing a normal SELECT statement?
SELECT  pdtid
  FROM  table
  WHERE col1 = 0 AND
        col2 = 0 AND
        col3 = 0

Or if you just want distinct entries, add the DISTINCT clause:
SELECT  DISTINCT pdtid
  FROM  table
  WHERE col1 = 0 AND
        col2 = 0 AND
        col3 = 0

EDIT
Following clarification that you'd like to return the pdtid ONLY when col1, col2, and col3 are 0 for all versions, see below.
Try the following which should show you how to achieve this using a nested table that SUMs the values for each of the columns before you SELECT from it:
CREATE TABLE #table (pdtid INT, [version] INT, col1 INT, col2 INT, col3 INT)
INSERT INTo #table (pdtid, [version], col1, col2, col3) VALUES (1, 1, 0, 0, 0), (1, 2, 0, 0, 0), (1, 3, 0, 0, 0), (2, 1, 0, 0, 0), (2, 2, 1, 1, 0), (3, 1, 0, 0, 0), (4, 1, 0, 0, 0), (4, 2, 0, 1, 0)

SELECT  pdtid
  FROM  (   SELECT  pdtid, SUM(col1) AS col1, SUM(col2) AS col2, SUM(col3) AS col3
              FROM  #table
              GROUP BY pdtid) a
  WHERE a.col1 = 0 AND
        a.col2 = 0 AND
        a.col3 = 0

DROP TABLE #table

