0

Am in need of some guidance on how to write a query.

There are the following tables:

tblWorkGroupProgramme

  1. WorkGroupID
  2. Programme ID

tblWorkGroup

  1. WorkGroupID
  2. WorkGroupName

tblUser

  1. UserID
  2. WorkgroupID

tblUserProgramme

  1. UserID
  2. ProgrammeID

The requirement is to find all those user id whose Workgroup name not like ‘%Insight%’ but ProgrammeID equals 59 as ProgrammeID 59 has to be allotted only to those users who have their Workgroup as ‘%Insight%’

Have been trying with all possible joins and sub queries, but couldnt get it. SO, any help, in the right direction would be of great use

1
  • Whenever you try something, post what you have tried! Commented Sep 6, 2012 at 10:48

2 Answers 2

1

here, try this one.

SELECT      a.UserID
FROM        tblUser a
                INNER JOIN tblWorkGroupProgramme b
                    ON a.WorkgroupID = b.WorkGroupID
                INNER JOIN tblUserProgramme c
                    ON c.ProgrammeID = b.ProgrammeID
                INNER JOIN tblWorkGroup d
                    ON b.WorkGroupID = d.WorkGroupID
WHERE       NOT (d.WorkGroupName LIKE '%Insight%') AND
            c.ProgrammeID = 59
Sign up to request clarification or add additional context in comments.

Comments

0

This is the answer that i came up with:

select a.UserID, c.WorkGroupName
from dbo.tblUserProgramme a 
where a.ProgrammeID = 59 AND 
a.UserID  IN (SELECT UserID  FROM tblUser a WHERE a.WorkGroupID IN
(SELECT WorkGroupID FROM tblWorkGroup
WHERE WorkGroupName like '%Insight%')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.