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 2008 Forums
 Transact-SQL (2008)
 [SOLVED]SELECT QUERY HELP

Author  Topic 

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-05-18 : 03:20:14
I have one table ENCOUNTER_PARTY

HAVING lots of columns but I am concern with only two columns.

ENCOUNTER_KEY, PARTY_ROLE_TYPE_KEY

( ENCOUNTER_KEY, PARTY_ROLE_TYPE_KEY ) is primary key for the table

What i want, I want to select only those ENCOUNTER_KEY which are having both the PARTY_ROLE_TYPE_KEY is 16 and 18.

Please help me out how can I do that.

Vaibhav T

If I cant go back, I want to go fast...

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-05-18 : 03:37:37
I got the solution but can any one tell me that
Is there any other solution possible ?


SELECT * FROM
(
SELECT ENCOUNTER_KEY FROM ENCOUNTER_PARTY WHERE PARTY_ROLE_TYPE_KEY = 16
) A
INNER JOIN
(
SELECT ENCOUNTER_KEY FROM ENCOUNTER_PARTY WHERE PARTY_ROLE_TYPE_KEY = 18
) B
ON A.ENCOUNTER_KEY = B.ENCOUNTER_KEY


Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-18 : 03:38:43
select ENCOUNTER_KEY from ENCOUNTER_PARTY ep
where PARTY_ROLE_TYPE_KEY = 16
and exists(select * from ENCOUNTER_PARTY ep2 where ep2.ENCOUNTER_KEY = ep.ENCOUNTER_KEY and ep2.PARTY_ROLE_TYPE_KEY = 18)



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

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-05-18 : 03:43:36
ah...! Thanks webfred...

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page
   

- Advertisement -