Which query will run faster

Hi,
I have following two tables:
SQL> desc customers
Name Null? Type
ID NOT NULL NUMBER
NAME VARCHAR2(20)
SQL> desc orders
Name Null? Type
CUST_ID NUMBER
ARTICLE_NR VARCHAR2(20)
PRICE NUMBER(5,2)
I want to find each customer's order with the highest price along with its respective article number and the customer's name.
Please let me know, which of the following query will work fast and why:
SELECT c.NAME, o.article_nr, o.price
FROM customers c,
(SELECT cust_id, article_nr, price,
ROW_NUMBER () OVER (PARTITION BY cust_id ORDER BY price DESC)
r
FROM orders) o
WHERE o.r = 1 AND c.ID = o.cust_id
SELECT NAME, article_nr, price
FROM orders o, customers c
WHERE c.ID = o.cust_id
AND (o.cust_id, price) IN (SELECT cust_id, MAX (price)
FROM orders
GROUP BY cust_id);
Thanks.

Your second version is selecting twice from the same table (orders). The first version needs only one read over this table. So there is a good chance that the first version is faster than the second.
However there is always a possibility depending on indexes etc. that it is otherwise.

Similar Messages

  • Which query will work fast

    Hi,
    Can anybody please suggest which query will work fast
    distinct role_cd is 1,2,3,4 and null in product table
    select * from product
    where nvl(role_cd,'4') not in '4'
    select * from product
    where role_cd in('1','2','3')
    I have 13 millions record in this table and there is no index on role_cd

    I tried this (11gR2) and get below, but still not sure if it is safe to say that the second one is better:
    create table product (role_cd char(2), id number);
    begin
    dbms_stats.set_table_stats( user, 'PRODUCT', numrows => 13000000 );
    end;
    explain plan for 
    select * from product where nvl(role_cd,'4') not in '4';
    Plan hash value: 427209646
    | Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |         |   650K|    10M|   319  (91)| 00:00:04 |
    |*  1 |  TABLE ACCESS FULL| PRODUCT |   650K|    10M|   319  (91)| 00:00:04 |
    Predicate Information (identified by operation id):
       1 - filter(NVL("ROLE_CD",'4')<>'4')
    explain plan for 
    select * from product where role_cd in('1','2','3');
    Plan hash value: 427209646
    | Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |         |   130K|  2158K|   287  (90)| 00:00:04 |
    |*  1 |  TABLE ACCESS FULL| PRODUCT |   130K|  2158K|   287  (90)| 00:00:04 |
    Predicate Information (identified by operation id):
       1 - filter("ROLE_CD"='1' OR "ROLE_CD"='2' OR "ROLE_CD"='3')

  • TFS 2012 - WebAccess - how to define which Query will run by default when navigating to WORK- WorkItems page

    When we nagivate in IE in TFS Web Access, to the WORK -> Work Items page, TFS runs the AssignedToMe query and focuses on it as sort of default query that runs in such event. We have some teams under the team project, but AssignedToMe is not sensitive
    to Team, only to Team Project, hence when navigating to the page of the specific team, this query shows the same per all teams :(.
    In order to bypass this, we'd like to set a specific team query to be the default one to run when navigating to the team's page, instead of AssignedToMe, and thus have the result specific to each team scope.
    Alternatively if it is possible to somehow filter AssignedToMe query according to Team Scope it would be great. Alas there's no @Team field yet, and we don't wish to create multiple AssignedToMe queries and name each specific to each team, nor do we wish
    to put team queries in MyFavorites while naming them specifically per team..
    Kindly advise, thank you

    Hi Moital,  
    Thanks for your post.
    As far as I know there’s no default way to the default query(AssignedToMe) in Work Items page, we usually add uses in different teams. If the user want to view the work items in one specific team, he can create a my query to filter work items according team
    field value.
    Yes, as you said there’s no @Team value in Team field to filter current team’s work items in work item query, so if you want create the shared query according team values, you need create this shared query for each team.
    For the Team field, please refer to the information in this document:
    https://msdn.microsoft.com/en-us/library/dn144940(v=vs.110).aspx.
    For this scenario, you can submit it to User Voice site at: http://visualstudio.uservoice.com/forums/121579-visual-studio. Microsoft engineers will evaluate them
    seriously.  
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Which query is running in package

    Hi,
    I created one package and run this package in toad
    like
    select reports_package.func_reports('ABC') from dual;
    I have 10 delete and 10 insert statement on this .
    How I will check which query is running iin database.

    799301 wrote:
    I have 10 delete and 10 insert statement on this .
    How I will check which query is running iin database.V$SESSION_LONGOPS holds information on SQL taking > 6 seconds to run but its not always possible to find expected entries in the V$ views
    If you're trying to figure out what is slow a better bet would be to perform trace or use DBMS_PROFILER to analyze the PL/SQL

  • Hello , please am having a problem with my iphone 5 , the battery runs out quickly , also if i turn on 3G it will run faster , 15 minutes and the iphone battery will be out , and my final problem is that is "no service " appears a lot can you help ?

    Hello , please am having a problem with my iphone 5 , the battery runs out quickly ,another problem also if i turn on 3G it will run faster , 15 minutes and the iphone battery will be out . My final problem is that  "no service " appears a lot  especially when opening wifi or 3G , can you help ?

    Your battery is running quickly because your cellular data connection is weak.
    Is your phone carrier a supported carrier:   Wireless carrier support and features for iPhone in the United States and Canada - Apple Support
    For your no service issues:  If you see No Service in the status bar of your iPhone or iPad - Apple Support

  • Have a G400, OS10.4.11. Need 10.5 or later to install a new printer. Which one will run best? How do I upgrade?

    Have a G400, OS10.4.11. Need 10.5 or later to install a new printer.
    1) Which one will run best?
    2) How do I upgrade?

    It's probably cheaper to buy a new printer & sell the existing on on ebay.
    I have the Cannon pixma mg3120  works fine for me with mac os x 10.4.11.  I am able to refill the color ink jet cartridge.  Press reset + color copy button for 10 seconds.
    http://www.amazon.com/Canon-MG3120-Wireless-All-In-One-5289B019/dp/B005TI2Q8M
    Mac OS® X v10.4.11 to v10.6.x
    http://www.usa.canon.com/cusa/consumer/products/printers_multifunction/photo_all _in_one_inkjet_printers/pixma_mg3120
    What is a G400?
    You may want to post machine info.
    blue apple > about this mac > more info button. Click on the hardware line. It has a little triangle in front of the word hardware.
    Leave out the serial number.
    Example:
    Machine Name: iMac
    Machine Model: PowerMac4,1
    CPU Type: PowerPC 750 (33.11)
    Number Of CPUs: 1
    CPU Speed: 600 MHz
    L2 Cache (per CPU): 256 KB
    Memory: 768 MB
    Bus Speed: 100 MHz
    Boot ROM Version: 4.1.9f1

  • TCP Communication - How can I remove the priority of which VI will run first?

    Hi. I would appreciate for any advise.
    I want to communicate (send data) to another PC using wireless radio. I am presently testing the shipped examples;
    TCP Communicator Active.vi and  TCP Communicator Passive.vi. I will run first the Passive.vi in the other pc (as
    indicated in the instruction) and then Active.vi on this pc.
    I want to remove or neglect the priority of which VI will run at first (either of the VI can run first).
    If in the case either one of the PC is not transmitting data, it will just trigger a LED or any kind of indicator.
    Can anyone helped me to do this? or is there any other example vi that will do it?
    Thanks a lot.

    Hi Mr Christian,
    i decided to use TCP/IP for peer to peer communication. I made an example VI of what i am doing but i cant make it right especially on the "Time out error". I would appreciate for any advise.
    Kindly see the attached VI's. The Crane 1 will be the Master or Server and Crane 2 and 3 are Slaves or Clients. Slaves VI will pass their data to Master while Master will distribute the data to each VI.
    As a rule, i have to run the Master or Server first and Slaves will follow.
    But as soon as i do this i am getting this Time Out error hence data are not being passed. I tried changing the values of time out constant but not lucky so far. I know that if i can fix this time out error, all the VI can communicate properly. I should see three moving cranes on each VI.
    Additional question; If all of the VI are running, and I intentionally Stop for instance Crane 3 (Slave), then it will show an error (LED) that Crane 3 data is not available. So far i can do this.
    But for instance I will run again Crane 3 (Slave), is there a way to RESET the connection programatically so that Master VI will once again accept the Crane 3 VI?
    Any advise I would greatly appreciate.
    Thanks a lot.
    Attachments:
    Crane 1 (Master).vi ‏40 KB
    Crane 2(Slave).vi ‏35 KB
    Crane 3 (Slave).vi ‏35 KB

  • How do I find out which query are running??

    My client is connecting to the database and running application through the web. From the Unix system, I know his job took 99% of CPU time and running for 1 hour already. Is there anyway I can find out which query are running in the Oracle?? So I can tune this query?? thanks..

    Hi,
    You can use the following query to identify it.
    set linesize 100
    set pagesize 100
    SELECT substr(sql_text,1,40) sql,executions, rows_processed,
    rows_processed/executions "Rows/Exec",
    hash_value,address
    FROM V$SQLAREA WHERE executions > 100 AND rownum <= 10
    ORDER BY executions DESC;
    Rgds,
    Dhana

  • Which Macs will run the IPhone SDK

    I Got spooked.
    'Turns out my PowerPC processor won't allow the IPhone SDK to install even though it doesn't give me any message indicating so.
    So I have to buy another machine and want to make sure it will run the IPhone SDK
    How about Intel Atom Processor N270 1.6GHz single core?
    Thank you so much. Answers to other questions have been very helpful.
    Jerry

    Sorry Orange,
    You answered about the duel core. I am now asking about a different machine. I am hoping to get answers about several so that it can also be helpful to others.
    Thanks tod,
    That's helpful. Since I am running 10.5.5 on a real Mac and it won't take IPhone SDK now I am wondering just what will take it.
    So now I know the Intel® Atom Processor® N270 in the Dell Inspirion minis won't.
    Will the IPhone SDK only run in a machine built by Apple and after they started to use Intel?
    Jerry

  • Which parser will do fast parsing of XML

    hi,
    Right now i am using sax parser for parsing my XML
    when many simultaneous access to this parser. the application hangs and nothing comes.
    can u please explain me why the reason this is happening ?
    next can u just me which parser will do best. and i don't want to cache my xml parsing.
    thanx and regards
    bala

    Best parser, it depends on the size of the document. For me Oracle parser seemed to be best for size=1 KB.
    Seenu.

  • Sql query is running fast in sqlplus but too slow in oracle why?

    Hi,
    I am executing one query in sqlplus . it gives output in two mins. when run that query in oracle it takes above 7hrs. why?
    what is root cause of this problem?

    SQLPLUS is a part of Oracle :) Do you mean SQL server
    Edited by: Maran.Viswarayar on Apr 19, 2010 11:49 PM

  • Which Photoshop will run on a late 2007 MacBook?

    I've been digging, and *think* that the correct answer is Photoshop CS4.
    Here are the specs on my MacBook:
    Processor  2.2 GHz Intel Core 2 Duo
    Memory  2 GB 667 MHz DDR2 SDRAM
    Graphics  Intel GMA X3100 144 MB VRAM
    Software  Mac OS X Lion 10.7.5 (11G63)
    As far as I've been able to determine, I cannot run Photoshop CS5 or 6 because of the VRAM required; also cannot run PS CS6 because it requires OSX 10.8, which the late '07 MacBooks cannot run.
    Any additional information would be appreciated!

    Hi all,
    Maverick on Late 2008 MBP seems a hot topic these days
    Well, I also have a late 2008 MBP 2.53GHz - 4 GB RAM, and I gotta change the HDD, since it became very slow. To be honest, I am very happy with 10.6.8: I think it is quite stable and all the apps I use are available for such an OS. However, I was thinking if it may be worth to upgrade it to Lion, Mountain Lion or Maverick. Pros and cons? Would you suggest me to do that? Thanks!

  • Hope Java 1.5 will run faster

    Above all languages, java is outstanding in nature but I cant imagine puttin up a simple swing application and find my application topping the task manager memory chart. Although I know the runtime loads before my program loads and its the one filling bulk of that memory space but i really believe SUN should work on making java really memory portable too
    Also, Java's idea is write once run anywhere but what do you guys think about write once, compile anywhere. Cant there be a scheme whereby you can easily compile your code to all platforms natives in a simple portable way. I know you guys in SUN may have being bombarded with this question several times as I always see "java to exe" questions and not that you never anticipated such opinions as this but ultimately I do believe that someday, we will need a laguage as beautiful as Java that runs native to the operating system. I dont know what C# is up to but I get a lot of fear in adopting anything microsoft
    Thanks

    Swing performance and memory use is suppose to be something they're focusing on in 1.4.2 and 1.5. Don't expect a huge change, but there will be improvements.

  • Upgrade to 10.4 or 10.5? Which one will be faster on iBook?

    Hi,
    I'm helping a friend upgrade their iBook G4 933 and need some advice.
    I've seen that 10.4 requires 256MB RAM and 10.5 requires 512 MB.
    She has 256 MB of RAM now and I'll be installing 1GB of RAM.
    Is 10.5 significantly faster than 10.4 on an iBook 933?
    Should I install 10.4 just because it requires less RAM?
    Thank you for your help.
    John

    Welcome to Apple Discussions!
    That machine also had a pretty small hard drive. Unless you desire to put in a larger hard drive, upgrading to Tiger might be better. See my FAQ* on disk space:
    http://www.macmaps.com/diskfull.html
    Leopard is faster for some things than Tiger, and Tiger some things more so than Leopard. It really depends how efficiently you use the interface. Find File in both operating systems is slower, though this thread shows a workaround:
    http://discussions.apple.com/thread.jspa?threadID=1861415
    Consider what applications you need, and whether or not compatibility of all of your applications necessitates updating to 10.4 or 10.5. See my update FAQ for other tips which may be of use*:
    http://www.macmaps.com/upgradefaq.html
    - * Links to my pages may give me compensation.

  • CS2 Filter Gallery "improved" preview is to slow, is there a classic mode that will run faster?

    The new filter gallery takes forever to preview. I assume this is because the preview area is so much bigger. I personally find it much more advantageous to preview a small portion of the image until I get the settings right, then run the filter on the entire image.
    Is there a way to run the filter functions in "classic mode", or reduce the size of the preview area so I don't have to wait forever each time I try a new setting?
    Thanks.
    Scott.

    No. The Filter Gallery is another brilliant disaster brought to us by the
    sometimes not so smart people at Adobe.
    Robert

Maybe you are looking for

  • Wich one of these or any FM Transmitter's work with a NANO?

    I am looking for a good FM Transmitter and i saw this Monster iCarPlay Wireless FM Transmitter for Apple iPod with Dock Connection at Best Buy and i was woundering if it will work with a NANO, this transmitter is Ipod Mini compatible. If not then the

  • Screensaver images (portrait) don't scroll anymore...

    Ever since the introduction of Lion my Screensaver only shows the centre of photo's shot in portrait mode. Where as in the past, these images used to scroll (or flow) either up or down using the zoom and fill screen functions in system preferences. L

  • Enhancements, User Exits

    Hi all, where can u find all the userits & enhancements available in Materials Management. thanks

  • Custom fields in ORDERS05 Idoc

    Hi Guys, For our scenario we have extended the custom IDOC ORDERS05 to add one custom field (ZZREF) in the header and one at the line item level (ZZLINEREF). Same fields have been appended to VBAK (Order header) and VBAP (Line items) tables. Now the

  • Resizing Pop-Up Window

    Hi All, This is a question posted before and havent got an answer, but I'm trying my luck again, bringing it to everyones attention. I have a WD component used to several other component to show Error,Warning, Info messages on a Pop up window. The cl