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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sql help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-10-25 : 09:10:14
what am i doing wrong

select participantid,count(participantid) from placements where count(participantid)=1 group by participantid


I just want to return all participantid's that have only one reocrds.

then I want to do a select * from placments where (and a bunch of criteria here) and participantid in(select participantid,count(participantid) from placements where count(participantid)=1 group by participantid)


am i going about this the wrong way?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-25 : 10:07:16
select
participantid
from placements
where count(participantid)=1
group by participantid
having count(*) = 1



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-25 : 10:52:42
select *
from placments p
join
(select participantid from placements group by participantid having count(*) = 1)dt
on dt.participantid = p.participantid
where (and a bunch of criteria here)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-10-25 : 10:58:09
thanks how do i fix this

i need to have the final query at the end as the sql is generated dynamically from my asp file


sql:select count(participantid) as countp from qryplacements where pos like 'F' and participantid is in (select participantid from placements group by participantid having count(*) = 1) and participantid is not null
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-25 : 11:04:50
Where is the problem?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-10-25 : 11:18:23
i'm getting

Incorrect syntax near the keyword 'in'.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-25 : 11:29:59
take away the the word 'is'.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-10-25 : 13:45:32
thanks :)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-25 : 14:31:51
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -