Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6854905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:41:30+00:00 2026-05-27T01:41:30+00:00

I have a table employee emp_id, ~10 other fields a1 b1 emp_type emp_id, effective_date,

  • 0

I have a table

employee

emp_id, ~10 other fields
a1
b1

emp_type

emp_id, effective_date, employee_type
a1            2/1/2011        RS
a1            9/3/2011        TU
b1            3/2/2011        RS

I’m doing something likke this:

select emp_id, ~10 other fields, employee_type
from employee e
inner join emp_type et
   on et.emp_id = e.emp_id
      and effective_date = (select max(effective_date) 
                            from emp_type et2 
                            where et2.emp_id = et.emp_id)

Is this the most efficient way of doing this? It doesn’t run too slow, but it’s a very common query in reports and I want to have the most efficient method. The emp_type has at most 4-5 records per employee, but usually just one. There are about 20,000 employees. I’ve seen a cross-apply solution but found that to be slower.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:41:31+00:00Added an answer on May 27, 2026 at 1:41 am

    I think a JOIN on a subquery would be more efficient – the whole result set is calculated once instead of once per row:

    select emp_id, ~10 other fields, employee_type
    from employee e
    inner join emp_type et
       on et.emp_id = e.emp_id
    Inner join (SELECT emp_id, MAX(effective_date) effective_date
                FROM Emp_type et2
                GROUP BY Emp_id) SubQ
    ON SubQ.emp_id = et.emp_id
    AND SubQ.effective_date = et.effective_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables TABLE : EMPLOYEE EMP_ID EMP_NAME EMP_TYPE 1 Shwetha 1 2
I have a table called Employee with the following fields: EmpID Salary Name I
I have a EMPLOYEE table with EMP_ID,EMP_NAME,EMP_ADDRESS. EMP_ID should have the following format. EMP001
Table: Relatives emp_id dep_id (composite primary key) We have to restrict one employee to
I have one Employee Table with the fields - EmpId, EmpName, Salary. Table Contain
sql server 2005 : i have a column empid in employee table with identity
I have a table which has employee relationship defined within itself. i.e. EmpID Name
Suppose I have table Person table Employee, which inherits Person. I want to get
I have a table: Employee (employeeID) EmployeeRank (rankID, employeeID) Now I have another table
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.