Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to re-write the query Expand / Collapse
Author
Message
Posted Sunday, December 8, 2013 7:10 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, July 9, 2014 9:51 AM
Points: 80, Visits: 332
Hi All,

Can someone help me to re-write this query to use one single coordinators table.

SELECT *

FROM personnel

WHERE Office IN ( SELECT Office_code
FROM coordinators
WHERE employee IN (
SELECT employee ID
FROM coordinators)
)

EO
Post #1520865
Posted Sunday, December 8, 2013 7:56 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, August 18, 2014 12:40 AM
Points: 1,314, Visits: 476
SELECT
p.*
FROM
personnel p inner join
coordinators c on p.Office=c.Office_code

As you are seeking an employee of the coordinators table between all employees in the coordinators table, the second IN clause is not needed at all.
Post #1520866
Posted Monday, December 9, 2013 6:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, December 9, 2013 6:43 AM
Points: 1, Visits: 20
SELECT P.*
FROM personnel P inner join coordinators C on
p.Office=c.Office_code


Post #1521058
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse