Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Query issue

Author  Topic 

editech
Starting Member

4 Posts

Posted - 2006-11-14 : 12:34:56
I have a table "TableA" which has field1,field2,field3.

field1 | field2 | field3 |
1 | 2 | 45 |
2 | 2 | 45 |
3 | 2 | 45 |

I want the the query to return the count(not counting duplicate field2 and field3 values) where Field2=2 and Field3=45
In this case I want the count to return only 1

Basically I dont want to count duplicates.

Thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-14 : 12:49:06
SELECT DISTINCT 1 from TableA WHERE Field2 = 2 AND Field3 = 45


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

editech
Starting Member

4 Posts

Posted - 2006-11-14 : 12:58:40
I want the count

quote:
Originally posted by Peso

SELECT DISTINCT 1 from TableA WHERE Field2 = 2 AND Field3 = 45


Peter Larsson
Helsingborg, Sweden





Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-14 : 13:02:04
You wrote you wanted 1 back as result?
quote:
Originally posted by editech

In this case I want the count to return only 1

SELECT Field2, Field3, COUNT(*), COUNT(DISTINT Field1) FROM TableA
WHERE Field2 = 2 AND Field3 = 45


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -