Home » SQL & PL/SQL » SQL & PL/SQL » Need a view that returns the most recent dates! Urgent, please help!
Need a view that returns the most recent dates! Urgent, please help! [message #214286] |
Mon, 15 January 2007 12:33 |
intermario_gr
Messages: 3 Registered: January 2007
|
Junior Member |
|
|
Hi,
I'm designing a database about an art-gallery, I am working on a view that returns some results from two tables, CUSTOMER and TRANSACTION. The view's code so far as well as the results returned are shown in the picture attached.
As you can see, for example, for WORKID=505 there are two rows. What I want to do however is only show, for each work, the row with the most recent date. That means that in the resulting table, there should be only one row for each WORKid, and that should be the one with the latest date.
Can you help me create the right view?
-
Attachment: DB_shot.JPG
(Size: 26.17KB, Downloaded 836 times)
[Updated on: Mon, 15 January 2007 12:42] Report message to a moderator
|
|
|
|
|
|
|
Re: Need a view that returns the most recent dates! Urgent, please help! [message #214323 is a reply to message #214314] |
Mon, 15 January 2007 19:04 |
intermario_gr
Messages: 3 Registered: January 2007
|
Junior Member |
|
|
Bill B wrote on Tue, 16 January 2007 00:00 | The problem is that you have multiple names with the same workid. If you truly only want one row and don't care which name is used then do the following.
select max(c.name) name,t.workid,max(t.purchasedate) purchasedate
from customer c, transaction t
where c.customerid = t.customerid
group by t.workid;
|
Well Bill, apparently that was the problem, I figured it out myself just before reading your reply. Although your solution returns just one row for each workID, it picks out the greater in the alphanumeric order, not the one the recent date belongs to! Thank you for the try anyway..
Littlefoot wrote on Tue, 16 January 2007 00:06 | Did you mean something like this, perhaps?SELECT c.name, t.workid, t.purchasedate
FROM CUSTOMER c, TRANSACTION t
WHERE c.customerid = t.customerid
AND t.purchasedate = (SELECT MAX(t1.purchasedate)
FROM TRANSACTION t1
WHERE t1.workid = t.workid)
|
Littlefoot, that's exactly what I'm talking about! I wanted the most recent owner of each work.. Thanks man
[Updated on: Mon, 15 January 2007 19:09] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Dec 08 19:42:00 CST 2024
|