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)
 Help in writing query with exist

Author  Topic 

Exir
Posting Yak Master

151 Posts

Posted - 2008-11-04 : 01:14:31
I have 3 tables like this:

table1: Rolename-RoleId
table2: UserId-ROleId
table3: PartName-...

I want to write a query that shows all fields of table3 which their partnames be same to Rolenames which their roleId are exist in group of roleIds with UserId=2

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-11-04 : 01:45:12
try this
SELECT t3.*
FROM table3 t3
INNER JOIN table1 t1 ON t1.Rolename = t3.PartName
INNER JOIN table2 t1 ON t1.ROleId = t2.RoleId
WHERE t2.Userid = 2

and also read about JOINs in BOL

"There is only one difference between a dream and an aim. A dream requires soundless sleep to see, whereas an aim requires sleepless efforts to achieve..!!"
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2008-11-04 : 02:12:15
Thanks for your response, but it didnt work : ( it always shows empty table
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-04 : 02:31:16
show some sample data from yourtables please
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2008-11-04 : 05:04:42
Thank you very much for your quick answering as always.
I found the problem and It worked successfuly : )
Go to Top of Page
   

- Advertisement -