Hi All
I am having problem in selecting the data from oracle. The problem is there are multiple enteries per customer, I want to select the latest updated value. I know the customer ids which has multiple entries corresssponding to them.
The columns are Cust_ID, Update_Date, Cust_Name,Cust_address.
Select ADDRESS_LINE1, LAST_UPDATE_DATE,ADDRESS_LINE2, ADDRESS_LINE3, CITY, STATE, ZIP,COUNTRY
from Customer_Table s where s.cust_id in (101,102,103,104,105,106)
Group By ADDRESS_LINE1, LAST_UPDATE_DATE,ADDRESS_LINE2, ADDRESS_LINE3, CITY, STATE, ZIP,COUNTRY
having .........(no idea)
I know this is not correct as I am still getting multiple records.
Any help will be useful.
Well, we don't really do oracle around these parts, but...
You should be able to say
count(*) > 1
in the having clause to get groups where there are > 1 rows in there.
|||I guess that the later means the one with latest LAST_UPDATE. I do not know if this works for "oracle", but it does for SQL Server.
select *
from Customer_Table s
where s.cust_id in (101,102,103,104,105,106)
and last_update = (
select max(a.last_update)
from Customer_Table as a
where a.cust_id = s.cust_id
)
go
AMB
|||Thanks for replying..I am sorry fro posting oracle query here..
I found the solution.....Thanks a lot...
No comments:
Post a Comment