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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:22:54+00:00 2026-05-13T23:22:54+00:00

Here is my select statement, SELECT TOP 1 EmpId, RemainingAdvance FROM SalaryDetails WHERE EmpId

  • 0

Here is my select statement,

SELECT TOP 1
  EmpId, RemainingAdvance 
FROM SalaryDetails
WHERE EmpId IN (SELECT Emp_Id
                FROM Employee
                WHERE Desig_Id='27')
ORDER BY CreatedDate DESC

When i executed SELECT Emp_Id FROM Employee WHERE Desig_Id='27' the results were

Emp_Id
16
17

But when i execute my first statement it gives me result for only 16 but no output 17…
I have records for both EmpId’s in SalaryDetails Table…..

EDIT:

Removing TOP 1 from my query i got this,

SELECT EmpId, RemainingAdvance FROM SalaryDetails 
where EmpId in (select Emp_Id from Employee where Desig_Id='27')
               ORDER BY CreatedDate DESC 

gave me

alt text

I want results for EmpId 16,17 ORDER BY CreatedDate DESC… Because my now my Desig_Id='27' and i will change it with a variable @CategoryId … So there may be ‘n’ number of employees based on @CategoryId

EmpId  RemainingAdvance
16                354.00
17                 0.00
  • 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-13T23:22:55+00:00Added an answer on May 13, 2026 at 11:22 pm
    SELECT SD.EmpId, SD.RemainingAdvance 
    FROM 
    SalaryDetails SD INNER JOIN 
       (SELECT SD2.EmpID, MAX(SD2.CreatedDate) AS MAXDate 
       FROM SalaryDetails SD2 GROUP BY SD2.EmpID) AS SD2
    ON SD.EmpID = SD2.EmpID
    INNER JOIN Employee E
    ON SD.EmpID = E.EmpID
    WHERE E.Desig_Id = '27' AND SD.CreatedDate = SD2.MaxDate
    

    Note: The query is written without trying it out.
    I suppose, this is what you are looking for.


    This variant also works (in at least one DBMS – namely IBM Informix Dynamic Server 11.50):

    SELECT SD.EmpId, SD.RemainingAdvance 
      FROM SalaryDetails SD
           INNER JOIN 
           (SELECT SD2.EmpID, MAX(SD2.CreatedDate) AS MAXDate 
              FROM SalaryDetails SD2 GROUP BY SD2.EmpID) AS SD2
           ON SD.EmpID = SD2.EmpID AND SD.CreatedDate = SD2.MaxDate
           INNER JOIN Employee E
           ON SD.EmpID = E.EmpID
     WHERE E.Desig_Id = '27'
    

    The compound join in the first ON clause might improve the performance of the query – but it is quite possible that the optimizer would hoist the ‘AND SD.CreatedDate = SD2.MaxDate’ condition anyway, meaning you wouldn’t spot any difference even if you examined the two query plans. I’m not quite sure of the best way to indent the table expressions after the main FROM clause.

    Edited by Jonathan Leffler – as requested by Shahkalpesh.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my current SQL statement: SEARCH_ALBUMS_SQL = SELECT * FROM albums WHERE title LIKE
Here is my SQL Statement which is not returning DISTINCT Thread Titles. SELECT DISTINCT
So here is the original query SELECT SUM(PickQty), SUM(ReqQty), AssignmentID, StopID FROM PickRequest GROUP
Here's an example of the query I'm trying to convert to LINQ: SELECT *
So firstly here's my query: ( NOTE:I know SELECT * is bad practice I
What am I missing here? I want to do a simple call to Select()
how do i incorporate a nested if statement in a select clause of a
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs

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.