[Show all top banners]

Gham-Pani
Replies to this thread:

More by Gham-Pani
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 SQL Help
[VIEWED 1719 TIMES]
SAVE! for ease of future access.
Posted on 03-15-05 9:38 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Table name INFORMATION


Item Eff_date Status

A 02/15/05 IN
A 01/15/03 AC
A 01/15/99 AC
B 02/15/05 AC
B 01/15/03 IN
C 02/15/07 AC
C 02/15/05 AC
C 01/15/03 IN


Criteria:

Get Item that has maximum Eff_date that is <= 03/15/05 and Status = 'AC'.

So basically,
the output should look like

Item Eff_date Status

B 02/15/05 AC
C 02/15/05 AC


I have

SELECT Item, Eff_date, Status
FROM INFORMATION A
WHERE
eff_date = (SELECT max(B.Eff_date) FROM
INFORMATION B
WHERE A.Item = B.Item AND Status = 'AC'AND Eff_date <= 03/15/05)

But I am getting the information for Item 'A' also which should not be in the output.

Any Idea guys???









 
Posted on 03-15-05 10:51 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

SELECT Item, Eff_date, Status
FROM INFORMATION A
WHERE
eff_date = max(Eff_date) AND Status = 'AC' AND eff_date <= 03/15/05);

I havent tested it but i think the code should be something like this.....

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 7 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
whats wrong living with your parents ?
Now Trump is a convicted criminal .
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters