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 8221797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:03:30+00:00 2026-06-07T14:03:30+00:00

I have two tables emp_master and transfer. for each employee_id in emp_master there can

  • 0

I have two tables emp_master and transfer. for each employee_id
in emp_master there can be multiple entries in transfer table. I want to get the latest
record from the transfer table based on date_of_tansfer and display it with data from
emp_master. I have written a query like this which is not working. I am getting a error
“EMP.EMPLOYEE_ID: invalid identifier”. I can get the details for single employee if i hardcode
it with that employee_id.. but how can i modify it to get data for all the employees..

select distinct emp.employee_id,trnsf.OU
from emp_master emp 
left join (select * from (select * from transfer where employee_id = emp.employee_id 
and date_of_transfer <= SYSDATE order by date_of_transfer desc) where rownum = 1) trnsfr
on trnsfr.EMPLOYEE_ID = emp.employee_id


CREATE TABLE "EMP_MASTER" 
   ( "EMPLOYEE_ID" NUMBER(10,0), 
     "FIRST_NAME" VARCHAR2(30 BYTE), 
     "MIDDLE_NAME" VARCHAR2(30 BYTE), 
     "SURNAME" VARCHAR2(30 BYTE), 
   ) 

 CREATE TABLE "TRANSFER" 
   (    "EMPLOYEE_SR_NO" NUMBER, 
        "EMPLOYEE_ID" NUMBER(10,0), 
        "DATE_OF_TRANSFER" DATE, 
        "OU" VARCHAR2(30 BYTE)
 ) 
  • 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-06-07T14:03:32+00:00Added an answer on June 7, 2026 at 2:03 pm

    The reason you are getting that error is the nesting level of your derived tables (sub-queries). A sub-query can “see” only the columns/tables from the immediate “parent” query (which in your case is the outer select that limits the result to one row).

    The following should do what you want:

    select distinct emp.employee_id, trnsfr.ou
    from emp_master emp 
    left join (
          select transfer.employee_id,
                 transfer.ou,
                 row_number() over (order by date_of_transfer desc) as rn
          from transfer 
          where date_of_transfer <= SYSDATE 
        ) trnsfr
        on trnsfr.employee_id = emp.employee_id and trnsfr.rn = 1;
    

    If date_of_transfer is really a “DATE” (i.e. no time involved) than you might consider using date_of_transfer <= trunc(SYSDATE) instead in order to “remove” the time from the SYSDATE result.

    • 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 a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two table Company and Employee. And there relation is Company(one) - Employee(many).
I have two tables objects and tags , each object having an id, and
I have two tables: emp (empno,ename) address(empno,address) emp can have 0 or more address.
Suppose I have two tables 1st table emp EmpID | EmpName|xyz...coloums 1. | Hrishi
I have a situation in Oracle where I have two tables - Table A
I have two tables TABLE : EMPLOYEE EMP_ID EMP_NAME EMP_TYPE 1 Shwetha 1 2

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.