SQL Select Stmt

55 pts.
Tags:
SQL Select
Need to create a sql stmt to find all the people who work on exactly the same projects and same hours as Smith.

Software/Hardware used:
sql 2008

Answer Wiki

Thanks. We'll let you know when a new response is added.

Just a single table with 3 columns (name,project,hours), the following works fine, but is there a better way to right this?

SELECT DISTINCT name FROM WorksOn a
WHERE NOT EXISTS
  (SELECT * FROM WorksOn b
   WHERE b.name = ‘Smith’ AND NOT EXISTS
      (SELECT * FROM WorksOn c
      WHERE a.name = c.name AND
      c.project = b.project AND c.hours = b.hours))

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    What problem are having with doing that? -- Tom
    125,585 pointsBadges:
    report
  • testaduro
    Not really a problem, just looking for an alternative to an existing stmt that I have created.
    55 pointsBadges:
    report
  • TomLiotta
    We need to know the table formats that are used. Your existing statement would also be a real help. -- Tom
    125,585 pointsBadges:
    report
  • carlosdl
    Can you explain why you are using those 'NOT EXISTS' conditions ?
    69,175 pointsBadges:
    report
  • msi77
    Maybeselect * from WorksOn a join (select * from WorksOn where name = 'Smith') b on a.project = b.project AND a.hours = b.hours and a.name <> b.name
    1,660 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following