Selecting FIRST record w/o fetching them all

Hi:
Is there a way to select any one record from a set or potentially many without having to actually fetch them all?
For example, I want to get the last name of only one person with the first name 'joe' from the employees table. I don't care which "joe" it finds. I don't want Oracle to go through the expense of fetching them all before arbitrarily givnig me one of them.
select last_name from employees where first_name = 'joe' and rownum = 1;
...works, but I suspect that Oracle's getting all "joe"s before giving me the one where rownum=1.
I suppose I could do this with a cursor... open... fetch... close (only do 1 fetch), but is there a more elegant way?
Thanks in Advance!

I dunno about that.
I ran a query fetching a single record from a table which has close to 5 million records. I limited with "and rownum = 1". It took a long time, but eventually returned a valid answer.
I ran looking at the query plan, with and without the "rownum = 1". This is what I found...
SQL> explain plan set statement_id = 'foo' for select name from imp_insts where rownum = 1;
Explained.
SQL> select lpad(' ',2*LEVEL)||operation||' '||options||' '||object_name qplan
from plan_table
where statement_id='foo'
connect by prior id=parent_id and statement_id='foo'
start with id=1; 2 3 4 5
QPLAN
COUNT
FILTER
TABLE ACCESS FULL IMP_INSTS
SQL> delete from plan_table;
4 rows deleted.
SQL> explain plan set statement_id = 'foo' for select name from imp_insts;
Explained.
SQL>
select lpad(' ',2*LEVEL)||operation||' '||options||' '||object_name qplan
from plan_table
where statement_id='foo'
connect by prior id=parent_id and statement_id='foo'
start with id=1;SQL> 2 3 4 5
QPLAN
TABLE ACCESS FULL IMP_INSTS
SQL> select count(*) from imp_insts;
COUNT(*)
4936477
I see the "FILTER" but no "STOPKEY". I didn't trust the query that I used to show the execution plan, so I spooled "select * from plan_table" to a file and grep'd for both "STOP" and "KEY". No mention of STOPKEY.
Oracle8i on Tru64.

Similar Messages

  • Formula to select first record on the column

    Hi All
    I need a formula to select a first record on the column, here is my query
    SELECT DISTINCT
                          dbo.OWOR.DocNum, dbo.OWOR.ItemCode, dbo.OWOR.Status, dbo.OWOR.PlannedQty, dbo.ITM1.Price, dbo.OWOR.Warehouse,
                          dbo.OWOR.PlannedQty * dbo.ITM1.Price AS Total
    FROM         dbo.OWOR INNER JOIN
                          dbo.ITM1 ON dbo.OWOR.ItemCode = dbo.ITM1.ItemCode
    WHERE     (dbo.OWOR.Status = 'P') OR
                          (dbo.OWOR.Status = 'R') AND dbo.ITM1.Price
    I need to select the first price on the price list for (dbo.ITM1.Price).
    Regards
    Bongani

    Bongani,
    Are you sure you don't want to link a pricelist? Because the unique key on ITM1 consists of ItemCode and PriceList and taking the first price for an item in ITM1 could result in kind of random prices for different items, depending on whice pricelist gets filled first for a certain item.

  • SQL command to select first record

    I would like to create an SQL command to link two tables on a field so that only the first matching record is selected. What would be the syntax for that? Thank you.

    Actually, that's not as simple as it sounds...  It also depends on your definition of "first", and what data you are looking for.
    For example, if you are looking for the earliest order date for each of your customers, you could do something like:
    select customer.code, customer.name, min(order.date) as First_Order_Date
    from customer, order
    where customer.code = order.cust_code
    group by customer.code, customer.name
    But if you also want the sales dollars for that first order, you'd have to do something like:
    select customer.*, firstOrder.first_order_date, sales.sales
    from customer
    join (
      select cust_code, min(date) as first_order_date
      from order
      group by cust_code
    ) firstOrder
    on customer.code = firstOrder.cust_code
    join (
      select cust_code, date, sum(sales) as sales
      from order_detail
      group by cust_code, date
    ) sales
    on firstOrder.cust_code = sales.cust_code and firstOrder.First_Order_Date = sales.date
    HTH,
    Carl

  • When I run the cursor over a template it shows several pages but when i select the document it only brings up the first two pages to edit. How do I see them all?

    When I run the cursor over a template it shows several pages but when i select the document it only brings up the first two pages to edit. How do I see them all?

    Skimming the templates in the Template Chooser shows you all of the pages available in the template once you open it. You can insert the one(s) you want, even more than one of any of them. Most users don't want or need all of the different pages, especially when they start the document.

  • I have about 300 podcasts in my itunes account.  They are all checked.  I want to uncheck them all and then just check back the ones I want to sync to my Ipod. Is there a way to select all and then uncheck them?

    I have about 300 podcasts in my itunes account.  They are all cheked so they sync to my Ipod.  I want to uncheck them all at once and then check just the ones I want to sync.  Is there a way to do a "select all" vs having to uncheck them one at a time?

    Plug in your ipod and navigate to it in itunes, then select the 'Podcast' tab from along the top.
    The first line where it says 'Automatically include' then two drop down boxes saying 'all unplayed' and 'all episodes' need changing.
    Change the drop down box that says 'all episodes' so that it reads 'selected episodes'
    You should then be able to go through your collection below and check only the podcasts you want to sync.
    You can do this show by show or if you clickt the show itself in this window, on a podcast by podcast basis.
    You can use these to drop down boxes to set all kinds of rules for syncing your podcasts, such as
    syncing all the latest podcasts, or just all of them or even the last 5 recent podcasts.
    I tend to go for 'Automatically include [all unplayed] of [selected episodes]
    Then just choose which podcasts I want to listen too,
    Hopefully this picture will help you find your way ^_^

  • Can't select multiple files without them all opening.

    I'm trying to move multiple files from another drive after having to have my HD replaced on a recall.  Most every time I try to select the files I want to move, every one of them opens in its own window, as well as opening programs when different types of files are selected.  I then have to close all the windows before I can move the files.  This wasn't a problem before the HD was replaced and I can't figure out what is different this time.
    I've tried selecting them by clicking on the first file and holding down the shift key and selecting the last one.  This selects all of them, but also opens all of them.  I then tried holding down the Command key and selecting them one at a time,  Tedious, but still opens every one I click on.  Have tried to use the mouse to draw a box around them, but this doesn't seem to work on the Mac. 
    This is Mac OS X 10.6.8
    Please help before I go totally nuts.  Nearly there now.
    Thanks
    Peg

    @ vsai :
    Do it properly man, I repeat,
    Open gallery ---> swipe from down-----> tap on share option-----> and then select multiple files by touching them... and now tap share icon.  
    If you find difficulty let me know.

  • How to select first several records from a database table by using select?

    Hi,
       I want to select first 100 records from a database table by using select clause. How to write it?
       Thanks a lot!

    hai long!
                 well select statement is used to retrive
    records from the database.
    following is the syntax to be used.
    1) select *  into corresponding fields of itab from basetable where condition.
    endselect.
      ex: select * into corresponding fields of itab from mara
                where matnr >= '1' and  matnr <= '100'.
           append itab.
          endselect.
    select * is a loop statement.it will execute till matnr is less than or equal to 100.
    note: you can also mention the required field names in the select statement otherwise it will select all the field from table mara.
    note: itab means your internal table name.
    hope you got the required thing.if it really solved u r problem then award me the suitable points.<b></b>

  • Selection first n(20 )records from result page

    Hi,
    I have a requirement where the the users  want to select first n(20)  record from the result page after applying the date filter . They want to see all results and then select the records say first 50.I do not want to select manually clicking( browsing on page).Any thoughts how this can be achieved  like adding  text box at frame so that I can give number .

    Hello Senthil,
    why you want to create one more textbox... you can achieve your requirement by entering 20 in "maximum number of fields". It will give first 20 results.
    If you want to add one more textbox for your purpose then tell me.
    Thanks and Regards,
    Amit Singh

  • Okay so i recorded a song but each part comes out as like take 1, i have 10 takes. how can i put them all together as one take, to make one song all in one take not small pieces of a song.

    okay so i recorded a song but each part comes out as like take 1, i have 10 takes. how can i put them all together as one take, to make one song all in one take not small pieces of a song. like i hit record and sang the entire song but when i hit play it was in pieces not just one song like it was in ten takes. is there any way i can blend it all into one take, to make one clear song?

    You're not very clear in stating your problem. Maybe it's terminology: "takes" in recording lingo (and in GB lingo) are different version of exactly the same part in a song, so you only want one of them in the end. Please tell us exactly what you did and what it is that you don't like.

  • How can I print multiple copies of the same photo onto one sheet of paper?  Do I have to Duplicate the photo in iPhoto and then select them all?

    How can I print multiple copies of the same photo onto one sheet of paper?  Do I have to Duplicate the photo in iPhoto and then select them all?

    no - you simply have to select the option to print mucliples of a photo on a page
    select the photo and go to the file menu ==> print - select the printer, paper size and print size and click customize - in the tool bar click on the settings icon (the gear looking thingy) and select "multiple of the same photo per page" and the preview will reflect this option showing a full page of the selected size photos
    LN

  • I just got the iPhone 5 and took it on a trip and took a bunch of photos on it. I just came home and hooked it up to my Mac for the first time and hit restore. All of my trip pictures disappeared. Is there any way I can retrieve them?

    I just got the iPhone 5 and took it on a trip and took a bunch of photos on it. I just came home and hooked it up to my Mac for the first time and hit restore. All of my trip pictures disappeared. Is there any way I can retrieve them?

    Did you by chance have photo stream turned on? If so then they might be there. When you restored your phone it deleted everything and they will be unretreivable from your computer.

  • TS4436 How do I select more than one picture and send them all to Facebook on my iPhone 4s with iso7?

    How do I select more than one picture and send them all to Facebook on my iPhone 4s with iso7?

    Hi, I want to thank you for all your information regarding my questions about sending more than one photo to Facebook. I did have to stop in at Verizon (where I bought my iPhone) to find out why I did not have a choice to choose Facebook with the export icon. The tech had to go into my setting and enable Facebook to recognize my iPhone. When I upgraded to iso7 somehow it could not recognize Facebook. Once he did this for me I was able to follow your advice and your answer solved my question. Thank you

  • I went to make a call this morning, and all my contacts have disappeared! How can I can them back? I only just entered them all the other day, this is my first iphone

    I went to make a call this morning and all my contacts have disappeareed, how do i get them back? This is my first iphone (4s) and i only just entered them all manually 4 days ago! Please help me!

    I entered them directly into my phone. Two days ago, I plugged it into my mac and synced it with itunes, but i didn't sync the contacts and they were still in there after.

  • How to select last record or first record value in a formula?

    Post Author: d111
    CA Forum: General
    I am using a query in a report that in addition to other columns, has a column of month labels like:
    There are no unique identifiers or sequence fields that can be used.   There is only 4 columns: the label and 3 percent columns.
    Jan07Feb07Mar07Apr07etc.
    I would like to show the range of months I am using in a label on the report showing the last and first records value. like: "Jan07 to Jun07".
    I can not see how to use the functions maximun or minimum since it sorts the months alphabetically.
    I would like to use a formula to just grab the first and last record.  I can't seem to find any information on this anywhere.
    Please advise and thanks.

    Post Author: bettername
    CA Forum: General
    Hmm... I suspect what you actually want is the minimum and maximum dates in the report, rather than the first and last records (even if they do happen to come out in date order). So you need to convert the text dates to real ones, and then pick the min/max values.
    If so, try these:
    Formula "ConvertToDate" (for details section) which converts your text field into a real date - suppress it once placed!:
    //Since you have 2-digit years, this conversion assumes that all your dates are >=year 2000
    numbervar the_month;if left({YourTable.YourField},3) = "Jan" then the_month:=1 elseif left({YourTable.YourField},3) = "Feb" then the_month:=2 elseif left({YourTable.YourField},3) = "Mar" then the_month:=3 elseif left({YourTable.YourField},3) = "Apr" then the_month:=4 else
    //...etc etc you fill in the rest!
    if left({YourTable.YourField},3) = "Dec" then the_month:=12;
    date(tonumber("20"+right({YourTable.YourField},2)), the_month, 1);
    Formula "Show Date Range" (for anywhere on the report) to show the min/max values of the dates;
    totext (minimum({@ConvertToDate})) + " to "+totext(maximum({@ConvertToDate}))
    If, however, you really just want the first and last records, and you want it at the top of your report as a title (eg: in the Report Header), then I can't see how it can be done without using a subreport that looks at the same dataset, but only displays the first and last records (using the formulas below).
    Stick this in the details section, and call it "HoldRecords" and suppress it:
    whileprintingrecords;stringvar first;stringvar last;if recordnumber = 1 then first:={YourTable.YourField}; //if its the first record that crystal is displaying, store it in a variableif recordnumber = count({YourTable.YourField}) then last :={YourTable.YourField} //and again, but for the last record
    Now create another formula, and put it into the report footer:
    evaluateafter({@HoldRecords});stringvar first" to "stringvar last //will display "Jan07 to Apr07"
    NOTE:  if you have the report ordered by anything, this'll throw the record numbering, and therefore the first and last records, therefore... urgh.
    Hope this helps...

  • HT4061 I have a iphone 4 and it updated itself the first of the week.  Now all of my appointments on the Calendar are gone.  Is there a way to get them back?

    I have a iphone 4 and it updated itself the first of the week.  Now all of my appointments are missing from the Calendar.  Is there a way to get them back?
    JE

    Hi cje24576,
    Welcome to the Support Communities!
    Are you using iCloud for your calendar?  When you go to the www.icloud.com website, do you see all of your entries there?  The troubleshooting steps in the article below should help you with this:
    iCloud: Troubleshooting iCloud Calendar
    http://support.apple.com/kb/TS3999
    Cheers,
    - Judy

Maybe you are looking for

  • Could not connect to the internet with my iPod Touch 4th Gen

    I set up an wireless ad-hoc network with my windows vista computer with WPA-2 Personal security type, however, while trying to connect it from the iTouch, it keep saying incorrect password. When I tried setting up another wireless ad-hoc network with

  • Error ORA12154 Database in NT and Linux

    I did not connected with my client WindowsNT with Oracle on linux. My NT is 4.0 (Oracle 805NT) and My linux RH5.2 (Oracle 805). I try connect NT in Linux and occur this error: ORA 12154 TNS: could not resolve this service name Thanks for all help. Gh

  • Finder crashes when trying to do anything with a jpeg

    I cannot view a jpeg by using the quick view spacebar function in finder. I also cannot compress the jpeg and any thing I do with the jpg crashes finder. Does any one know why this is happening or knows how to fix it?? Thanks

  • Is it possible to change my iPad panel as

    I

  • LMS 4 Template Center issues

    For years we have used baseline templates to deploy basic configurations to LAN switches as part of the staging process.  Since the baseline templates were developed more as a compliance check mechanism, I thought I would try to move this function ov