Output the number of rows returned in a query

How do I find out the number of rows that are returned in a query?
COUNT function I guess can only be used when there is only one table involved. How do I do it for multi table query like JOIN?
For example
SELECT emp.first_name, emp.last_name, jobs.age FROM employees emp, jobs
WHERE emp.employee_id=jobs.employee_id

Hi,
You can get the num of rows info
select count(*) from (SELECT emp.first_name, emp.last_name, jobs.age FROM employees emp, jobs
WHERE emp.employee_id=jobs.employee_id) ;
regards
Jafar
http://www.oracledbarea.blogspot.com

Similar Messages

  • Getting the number of rows returned from ResultSet

    Hi,
    Does anyone know a method to get the number of rows returned with a query using the Resultset class?
    Thanks.

    Hi 281080,
    If your database and JDBC driver support it, in order to use the solution that da-alexj has suggested, you need to create a 'scrollable' "ResultSet" -- the javadoc for method "createStatement()" (in class "java.sql.Connection") has more details.
    However, I have found with Oracle 8.1.7.4 database and Oracle (thin) JDBC driver, that part of their implementation of the "last()" method (in class "java.sql.ResultSet") is to actually iterate through the entire "ResultSet" in order to reach the last row. If your "ResultSet" is very large (I tested it with a 100,000 row "ResultSet"), this will take a long time.
    Just wanted to make you aware of that.
    Of-course, this may be irrelevant to you since I didn't see any mention in your post of what database and JDBC driver you are using.
    Hope this has helped you, anyway.
    Good Luck,
    Avi.

  • Number of rows returned in a query

    Is there a way to get the number of rows returned from a query without itterating through the itterator?
    Thanks,
    Yon

    No.
    Because rows are not all returned until you start interating.
    Some times I have seen people do a count query before the normal query, this helps out if you need a count to set things up.

  • How can I limit the number of rows returned by a select stat

    How can I limit the number of rows returned by a select
    statement. I have a query where I return the number of stores
    that are located in a given area.. I only want to return the
    first twenty-five stores. In some instances there may be over
    200 stores in a given location.
    I know is SQL 7 that I can set the pagesize to be 25....
    Anything similiar in Oracle 8i?
    null

    Debbie (guest) wrote:
    : Chad Nale (guest) wrote:
    : : How can I limit the number of rows returned by a select
    : : statement. I have a query where I return the number of
    : stores
    : : that are located in a given area.. I only want to return the
    : : first twenty-five stores. In some instances there may be
    : over
    : : 200 stores in a given location.
    : : I know is SQL 7 that I can set the pagesize to be 25....
    : : Anything similiar in Oracle 8i?
    : If you are in Sql*Plus, you could add the statement
    : WHERE rownum <= 25
    : Used together with an appropriate ORDER BY you
    : could get the first 25 stores.
    Watch out. ROWNUM is run before ORDER BY so this would only
    order the 25 selected
    null

  • Can I limit the number of rows returned on a Select?

    Can I limit the number of rows returned on a Select statement? I would be using JDBC in a Java program.

    Use Java prepared statements with the equivalent of this SQL*plus script:
    VARIABLE n number
    EXEC :n := 3;
    SELECT rownum FROM all_objects WHERE rownum <= :n;
        ROWNUM
             1
             2
             3
    EXEC :n := 5;
    SELECT rownum FROM all_objects WHERE rownum <= :n;
        ROWNUM
             1
             2
             3
             4
             5

  • Need to know how to limit the number of rows returned on Oracle

    MS SQL Server has a command called 'set row count'.
    We are trying to find similar one on Oracle.
    What we are trying to do is that instead of using rownum in the query statement, we would like to find way to limit the number of rows returned. I understand that we can use JDBC resultSet object, but that's not what we want.
    I know Oracle has one called arraysize, but this would not limit the number of rows returned either.
    Pease help.
    Thanks

    I understand that we can use JDBC resultSet object, but that's not what we want.I'm not sure which feature of ResultSet you use and which not.
    But if this question has anything to do with JDBC (that's the forum where you put it), I'd recommend to use Statement.setMaxRows(). This will limit the count of rows which your statement will fetch into it's ResultSet.

  • How do you limit the number of rows return from query?

    How do you limit the number of rows return from query? Do all databases support this kind of feature?

    i think the standard is limit
    to get the top 30
    select * from mytable LIMIT 30;returns the first 30 rows
    also if you want a range
    select * from mytable LIMIT 10,30;returns 30 rows starting from 10
    this last one is useful for displaying ranges... something similar happens in these forums when viewing topics and messages

  • How to get number of rows return in SELECT query

    i'm very new in java, i have a question:
    - How to get number of rows return in SELECT query?
    (i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
    Thanks.

    make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
             String sql = "select * from testing";
             PreparedStatement ps =
              con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs = ps.executeQuery();
             rs.last();
             System.out.println("Row count = " + rs.getRow());
             rs.beforeFirst();~Tim
    NOTE: Ugly, but does the trick.

  • How to restrict number of rows returned in a query

    Hi frnds,
    I'd like to restrict number of rows returned by my query to some 10 rows. how to do that.When I try doing with the rownum<10 its giving results for a particular dept and that too some 6 rows only...btw I'm grouping my table and includes joins from many a table and am ordering the table results by a column.. How to do this..

    776317 wrote:
    Hi frnds,
    I'd like to restrict number of rows returned by my query to some 10 rows. how to do that.When I try doing with the rownum<10 its giving results for a particular dept and that too some 6 rows only...btw I'm grouping my table and includes joins from many a table and am ordering the table results by a column.. How to do this..
    TELL ME HOW MANY ROWS YOU HAVE IN TABLE?
    Because you have only *6 rows* in you column, if you less than 10 rows then it displays only containied/exist rows. nothing much
    select ename,empno from emp where rownum < 10;Thanks

  • How to get the number of rows returned by a report?

    Hi,
    I'm developing my first application in APEX and so far everything seems fine, except I can't figure out this very simple thing: I have a report based on a PL/SQL block returning an SQL string. I'd like to have a message (something like "X rows returned") just before the report. The closest thing I could find was "X to Y out of Z" in the pagination styles, but that's not what I want. Also I don't think running the same query to get COUNT() is wise.
    Any help would be appreciated.
    Thanks,
    Konstantin

    My guess is that it only shows the number of rows it has retrieved. I believe the defailt is for it to only retrieve 50 rows and as you page through your report it retrieves more. So this would just tell you how many rows was retireved, but probably not how many rows the report would contain if you pages to the end. Oracle doesn't really have a notion of total number of rows until the whole result set has been materialized.

  • Get the number of rows returned by a dataProvider

    hi
    I am using a [Bindable] variable that I am setting and using
    as a DataProvider (coming from a web service) for a DataGrid within
    my Flex 2 application.
    is there a way of knowing the amount of rows that the
    dataProvider is returning???
    as I want to do a calculation to set the height of the
    dataGrid depending on the amount of rows being returned by the
    dataGrid!
    any suggestions...?
    Thanks,
    Jon.

    that only seems to count the default number of rows (height)
    of the datagrid..... i.e. 7.
    I need to know the number of rows being returned from the
    dataProvider - i.e. the number of rows coming through the
    webService from the database etc.....
    Thanks,
    Jon.

  • Limiting the number of rows returned by SQL or ResultSet

    Hello,
    I'm trying to limit the number of rows that my application receives to a user-specified value. The user is asked how many accounts they want returned and I want to limit my ResultSet to this amount. I'd prefer to set up the SQL to do this if possible rather than waste time returning more records than necessary to the ResultSet.
    If it's not possible to limit the SQL, how can I limit the number when processing the ResultSet?
    Or, is there any way to setup a cursor in JDBC without being able to use Stored Procedures?
    I'm going up against DB2 using DB2Connect.
    Thanks!

    It's not surprising that you are confused because the documentation doesn't bother to explain what the "fetch size" actually is, it just says that setFetchSize sets it and getFetchSize gets it. As I understand it from some other documents I read about JDBC, the fetch size is a number that may be used internally by the JDBC driver. Here's an example of how I understand it (others, I know you will feel free to correct me if you disagree):
    When the driver produces a result set with a very large number of records, it has to generate those records and deliver them to the system that requested them. If the database is not on the same system, then those records must all travel over the network. It could be a performance problem if you had to wait for (say) 80,000 records to travel across the network. Enter the fetch size. If you set the fetch size to 100, then the driver will bring the records across in batches of 100, as the program calls for them. Now, this buffering is transparent to your program; the driver doesn't tell you that it's getting another batch and you can't tell it to get another batch. So it is not a solution to the problem that everybody has here, namely how to display your records 10 per page and allow the user to go back and forth among those pages, like search engines do.

  • Need to limit number of rows returned by a query

    Hi. Is there a way to limit the rowsets returned to me in a query? I need to get the first 100, then the next hundred, etc until there are no more rows left to retrieve. Someone told me that I should use a cursor to do this. Does anyone have a specific example? Can this be done with a combination of SQL/JDBC?
    Thanks in advance...bbetta
    null

    if you are talking about limiting the number of rows to be returned to the calling program to a managable number of rowa ...
    for example the result set size would be 5000 rows and you want to get them in batches of 50 or 100 ..
    see the attached link :
    JDBC Code Templates
    http://technet.oracle.com/sample_code/tech/java/sqlj_jdbc/htdocs/templates.htm#BatchSize
    if you want the server side transaction to only return the first 50 or 100 rows even though the result set has more ... then
    another approach is required -- possibly as suggested above ...

  • How do you change the number of rows returned by an advanced datagrid...Only displays 1000 rows....I

    I am using coldfusion to query an oracle table....Query returns approximately 2000 rows, however the max rows the datagrid will display is 1000.  Does anybody know how to change this...THANKS!!

    Thanks so much for your answer that sounds like a good idea...
    I found the answer to my initial problem...In my coldfusion I had set maxrows = 1000.  So the datagrid was always returning 1000 records even when a lot more than that should have been returned...When I removed the maxrows parameter in the coldfusion code, my datagrid was now been populated with the correct number of rows...
    thanks again for your help,
    Ronnie Raigrodski (Aka -- FlexNerd)

  • Is it possible to count the rows returned from a query?

    Hello,
    When using JDBC is there anyway of finding out the number of
    rows returned from a query before actually getting each row?
    In Forms 4.5 you can use the count_query function, does anyone
    know of an equivalent function or work around in JDBC and/or
    SQLJ?
    Thanks.
    null

    Pasi Hmlinen (guest) wrote:
    : Try
    : SELECT COUNT(*) FROM the_table WHERE <conditions>;
    : Hope this helps,
    : Pasi
    Thanks for the advice, I'm currently using SELECT COUNT(*) but
    I'm looking for a more efficient way of doing it. If I SELECT
    COUNT each time then I have to prepare and execute a SQL
    statement each time. What I want to do it execute a single SQL
    statement to return my results and somehow find out the number
    of rows in the resultset without having to go back to the
    database.
    Gethin.
    null

Maybe you are looking for

  • FA and PO Charge Account?

    Dear all, I have 2 questions on FA and PO and we are using R12. For FA, we have 2 asset books (USD and CNY). Any solution or control for FA addition into different company not ledger book. e.g.) FA of USD was wrongly manual process addition into CNY.

  • I have a problem with Mail, I reinstalled my DVD, thinking I can update back to 10.6.8, A pop-up window states it can't be used with this SL Sy. What do I do?

    I am using S/L OS 10.6.8 and my install disk is 10.6.3. I cannot find any clue to update the mail from my disk, I tried to find a path thru the Software Update to no avail. My back-up of HD, is the same versions as my install disk. Thanks Guys Funopt

  • Reg:Receiver Mail Adapter

    Hi ..   I am using Mail adapter at reciever side. I am using Mail package for this. I have selected SMTP as Transport Protocol. and I have selected XIPAYLOAD  as Message Protocol in URL i ahve given in the below format. SMTP://host ip address:port I

  • How to process stucked holding messages in the Adapter Engine.

    Hi experts, This question is may be familier to all... There are thousands of messages are in holding status in the Adapter engine in RWB. I tried to found system error in these messages. There is no system error from the last in my investigation. I

  • Not able to submit Article

    Hi , When i try to submit my article through 'Content Management system ' , In third step when i give location for file to be uploaded in my computer , It waits in that Third step for more that 3 hours . It is in that screen for long time .  So i cam