<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: only retrive LAST rown of sql query in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684100#M932453</link>
    <description>Ian&lt;BR /&gt;&lt;BR /&gt;If you are talking Oracle...&lt;BR /&gt;As Steve says, without an 'order by' statement the order in which Oracle will retrieve your rows is indeterminate and may not be consistent between successive invocations of the same query.&lt;BR /&gt;If you *do* use 'order by' you can combine it&lt;BR /&gt;with "WHERE ROWNUM = nn"; ROWNUM is a pseudocolumn but as it is assigned as rows are retreived (ie before they are sorted according to 'order by') it still may not give you what you want.&lt;BR /&gt;In any case to retrieve the last row of a query is not so easy, you would have to do something like &lt;BR /&gt;&lt;BR /&gt;select * from emp &lt;BR /&gt;where rownum = (select count(*) from emp)&lt;BR /&gt;&lt;BR /&gt;Better to reverse the query and &lt;BR /&gt;select ..&lt;BR /&gt;where rownum = 1&lt;BR /&gt;&lt;BR /&gt;Hope this helps. If you have access to MetaLink there is plenty more about rownum.&lt;BR /&gt;&lt;BR /&gt;Graham&lt;BR /&gt;</description>
    <pubDate>Mon, 18 Mar 2002 08:54:57 GMT</pubDate>
    <dc:creator>Graham Cameron_1</dc:creator>
    <dc:date>2002-03-18T08:54:57Z</dc:date>
    <item>
      <title>only retrive LAST rown of sql query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684097#M932450</link>
      <description>Hi&lt;BR /&gt;Can someone tell me how to only retrieve the LAST row of an sql query (equivalent of unix "tail -1 " command)&lt;BR /&gt;I have tried reversinq the order by clause and using "rownum = 1" but the ronwums are allocated before the order by&lt;BR /&gt;&lt;BR /&gt;Any help much appreciated&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Ian</description>
      <pubDate>Fri, 15 Mar 2002 11:38:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684097#M932450</guid>
      <dc:creator>Ian McClement_1</dc:creator>
      <dc:date>2002-03-15T11:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: only retrive LAST rown of sql query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684098#M932451</link>
      <description>Hi,&lt;BR /&gt;It's been a while, but something like&lt;BR /&gt;select field01, field02, field03&lt;BR /&gt;from your_table &lt;BR /&gt;where field01 = (select max(field01)&lt;BR /&gt;from your_table);&lt;BR /&gt;might work since you do seem to have fields you can order the table by.&lt;BR /&gt;&lt;BR /&gt;Hope this helps,&lt;BR /&gt;Tom Geudens</description>
      <pubDate>Fri, 15 Mar 2002 11:50:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684098#M932451</guid>
      <dc:creator>Tom Geudens</dc:creator>
      <dc:date>2002-03-15T11:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: only retrive LAST rown of sql query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684099#M932452</link>
      <description>You definitely need an order by, otherwise the order returned is undefined, depending on whether any rows are cached in buffers.&lt;BR /&gt;&lt;BR /&gt;If your query was something like:&lt;BR /&gt;select name, a_number &lt;BR /&gt;from mytab&lt;BR /&gt;order by a_number&lt;BR /&gt;&lt;BR /&gt;and you want the last row returned from above, then you can change it to&lt;BR /&gt;&lt;BR /&gt;select first 1 name, a_number&lt;BR /&gt;from mytab&lt;BR /&gt;order by a_number desc&lt;BR /&gt;&lt;BR /&gt;This is informix syntax, don't know about oracle/sybase etc.&lt;BR /&gt;&lt;BR /&gt;Otherwise you can do it the hard way (i.e. write a stored procedure or program to unload the rows, tail -1 on the file and read it back in returning one row)&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Mar 2002 13:07:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684099#M932452</guid>
      <dc:creator>Steve Lewis</dc:creator>
      <dc:date>2002-03-15T13:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: only retrive LAST rown of sql query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684100#M932453</link>
      <description>Ian&lt;BR /&gt;&lt;BR /&gt;If you are talking Oracle...&lt;BR /&gt;As Steve says, without an 'order by' statement the order in which Oracle will retrieve your rows is indeterminate and may not be consistent between successive invocations of the same query.&lt;BR /&gt;If you *do* use 'order by' you can combine it&lt;BR /&gt;with "WHERE ROWNUM = nn"; ROWNUM is a pseudocolumn but as it is assigned as rows are retreived (ie before they are sorted according to 'order by') it still may not give you what you want.&lt;BR /&gt;In any case to retrieve the last row of a query is not so easy, you would have to do something like &lt;BR /&gt;&lt;BR /&gt;select * from emp &lt;BR /&gt;where rownum = (select count(*) from emp)&lt;BR /&gt;&lt;BR /&gt;Better to reverse the query and &lt;BR /&gt;select ..&lt;BR /&gt;where rownum = 1&lt;BR /&gt;&lt;BR /&gt;Hope this helps. If you have access to MetaLink there is plenty more about rownum.&lt;BR /&gt;&lt;BR /&gt;Graham&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Mar 2002 08:54:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684100#M932453</guid>
      <dc:creator>Graham Cameron_1</dc:creator>
      <dc:date>2002-03-18T08:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: only retrive LAST rown of sql query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684101#M932454</link>
      <description>If you're talking Informix Dynamic Server, try "SELECT FIRST 1 * FROM .... WHERE ... ORDER BY..."&lt;BR /&gt;Of course, you'll have to reverse your Order-by clause as well.</description>
      <pubDate>Mon, 18 Mar 2002 09:31:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684101#M932454</guid>
      <dc:creator>Deepak Extross</dc:creator>
      <dc:date>2002-03-18T09:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: only retrive LAST rown of sql query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684102#M932455</link>
      <description>Hi Ian,&lt;BR /&gt;&lt;BR /&gt;In relational database, there is no order in the extraction of rows, since it's based on algebric sets which do not support order between the constituants of these sets.&lt;BR /&gt;&lt;BR /&gt;So, suppose that you are issuing a sql statement that matches 10 rows, the output order of these rows will be a random order and no matter to fix which one appear at last or at the begining. &lt;BR /&gt;Then, if you try to print only one row ( with special mechanism ) you will have a different result each time you run this sql statement while data didn't changed.&lt;BR /&gt;&lt;BR /&gt;And this is completely false !&lt;BR /&gt;&lt;BR /&gt;Conclusion : In relational algebra, these is no order in sets.&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;Magdi</description>
      <pubDate>Mon, 18 Mar 2002 11:13:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684102#M932455</guid>
      <dc:creator>Magdi KAMAL</dc:creator>
      <dc:date>2002-03-18T11:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: only retrive LAST rown of sql query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684103#M932456</link>
      <description>If you are talking Oracle/SQL*Plus, try this:&lt;BR /&gt;&lt;BR /&gt;echo "set heading off pages 0 feed off heads off&lt;BR /&gt;select * from tab;" | sqlplus -s user/pass | tail -1&lt;BR /&gt;&lt;BR /&gt;Substitute your SQL, of course.&lt;BR /&gt;&lt;BR /&gt;Not a total Oracle solution, but works.</description>
      <pubDate>Mon, 18 Mar 2002 16:19:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684103#M932456</guid>
      <dc:creator>Eric Ladner</dc:creator>
      <dc:date>2002-03-18T16:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: only retrive LAST rown of sql query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684104#M932457</link>
      <description>Hi&lt;BR /&gt;if you can order on one of the fileds use this sql syntax&lt;BR /&gt;&lt;BR /&gt;select ename,job from &lt;BR /&gt;  (select ename,job from emp order by job,ename desc)&lt;BR /&gt;  hwere rownum &amp;lt;=1;&lt;BR /&gt;&lt;BR /&gt;that should retrieve the last record in the ordered output of the query.&lt;BR /&gt;&lt;BR /&gt;Replace the column names and table name by what you need</description>
      <pubDate>Fri, 22 Mar 2002 13:46:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/only-retrive-last-rown-of-sql-query/m-p/2684104#M932457</guid>
      <dc:creator>Reinhard Burger</dc:creator>
      <dc:date>2002-03-22T13:46:20Z</dc:date>
    </item>
  </channel>
</rss>

