•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Oracle section within the Web Development category of DaniWeb, a massive community of 456,564 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,584 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Oracle advertiser: Programming Forums
Views: 5812 | Replies: 7
![]() |
•
•
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,445
Reputation:
Rep Power: 4
Solved Threads: 87
•
•
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,445
Reputation:
Rep Power: 4
Solved Threads: 87
•
•
Join Date: May 2007
Posts: 22
Reputation:
Rep Power: 2
Solved Threads: 0
here's the correct answer that i figured out:
That's not a great way to do it, because you've got a subquery. Doing two queries when only one is needed.
You'll find it should perform faster if you do a join and then get the max all in one queery, something like below. It depends on how Oracle optimises it though, performance issues can be fun to play with. In general the following will be better than what you've got above:
Having said that, it really does depend on a number of factors which I won't get into for now.... anyway you have some options now
SELECT cu.cust_name,
od.order_amount
FROM customers cu,
orders od
WHERE cu.cust_id = od.cust_id
and od.order_date =
(select max(order_date) from orders od
where od.cust_id = cu.cust_id)That's not a great way to do it, because you've got a subquery. Doing two queries when only one is needed.
You'll find it should perform faster if you do a join and then get the max all in one queery, something like below. It depends on how Oracle optimises it though, performance issues can be fun to play with. In general the following will be better than what you've got above:
select cu.cust_name, od.order_amount, max(order_date)
from customers cu
join orders od
on (cu.cust_id = od.cust_id)
group by cu.cust_name, od.order_amountHaving said that, it really does depend on a number of factors which I won't get into for now.... anyway you have some options now
Last edited by peter_budo : Mar 10th, 2008 at 9:23 pm. Reason: Keep It Organized - please use [code] tags
![]() |
•
•
•
•
•
•
•
•
DaniWeb Oracle Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- mysql_fetch_array(): supplied argument is not a valid MySQL (PHP)
- AJAX generated <select> and FIREFOX (JavaScript / DHTML / AJAX)
- How to select the Last row from a table..using Mysql (MySQL)
- can i select the 2nd row/record from a table (MySQL)
- javascript to add select button (JavaScript / DHTML / AJAX)
- ASP .NET database hit counter (ASP.NET)
- Find and Replace (Database Design)
Other Threads in the Oracle Forum
- Previous Thread: oracle9i operating system audit file location
- Next Thread: Administrating a database using VB



Linear Mode