question

varun.rk avatar image
varun.rk asked

Joining morethan 2 tables these tables have duplicates records

Hello all, My requirement is i need to join 6 tables in this 6 table one table name is EMPLOYEEMENTHISTORY in this table in this table columns are like employeid as primarykey, memberid as foreignkey, jobtile , startdate, enddate. when user registered user will be enter more than one jobtile , but i need to show the most recent jobtitle(it means the max startdate jobtitle). And my 6 tables some tables have duplicate records, so how i want to write a storeprocedure with joining these 6 tables and also i need to show recent jobtile. please tell me any one. Thanks
sql-server-2008tsqljoins
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
Not knowing more than you told us, it's going to be difficult to give you a precise answer. For a precise answer, please post the entire data structures you're dealing with. For a general answer, I'm assuming that enddate must be correlated to the changes in job titles. Can you then just put: WHERE enddate IS NULL. If not, do you have a last modified date or something along those lines. Then you can SELECT TOP 1 from your EMPLOYEEMENTHISTORY table as a derived table like I [show in this article][1]. [1]: http://www.simple-talk.com/sql/database-administration/sql-strategies-for-versioned-data/
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.