Select specific number of rows
i'm listing all data entries in a database.
for that i want to select the 1st ten entires, then the next ten and so on ordered
by date_column.
how can i do that? is it possible with rownum?
in mysql/php i did it with limit
$query = "select * from article where parent_id=0 order by date desc, time desc limit $select, 10";
please email me.
thanks for help
chris
but what about rownum if i want the
records from 10-20?
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Chen Zhao ([email protected]):
If you are using Oracle 8i, you can use ROWNUM to specify the specific number of records. You can see the ROWNUM by querying:
SELECT *
FROM (SELECT column_name FROM table_name ORDER BY column_name)
WHERE ROWNUM<10
CHEN<HR></BLOCKQUOTE>
null
Similar Messages
-
Select a specific number of rows in query
How can a specific number of rows be selected in a query? For example, a query retrieves 30,000 records and I want to retrieve the output by groups of 5,000. I want the query to retrieve the first 5,000 records, then the next 5,000 records etc. I tried rownum but that does not work.
Thanks,
PANYNot AGAIN. Please...........
Do you know how to Google? Search forum?
Why do you ask this boring FAQ AGAIN?
Sybrand Bakker
Senior Oracle DBA
Experts: Those who know how to search. -
Getting a specific number of rows
Hi,
I would like to know how to get a specific number of rows. For example, I want to page data in my web application, so I'd like to be able to retrieve just 25 rows in my SELECT statement. I searched and I couldn't see anything under the obvious keywords of LIMIT and TOP (as used by other database vendors) so I'm wondering if possible, what do I need to do - a pointer to the relevant documentation would be helpful also.You can achieve this with rownum
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns009.htm#i1006297
Best regards
Maxim -
Fitching a specific number of rows
hi all
i want to fitch a specific number of rows in my query
not all matches (SQL2000 Server )
what command in my sql query can be placed to do so
thanksset rowcount n
-
Return specific number of rows depending on the data in a column in table
Hi,
I have a table named orders which has column orderid and noofbookstoorder in addition to other columns.
I want to query the orders table and depending on the value of the 'noofbookstoorder' value return that number of rows.
Eg
Orderid noofbookstoorder
1 1
2 3
3 2
when I query the above data saying
select * from orders where orderid=2;
since it has noofbookstoorders value as 3 the query should return 3 rows and when I query
select * from orders where orderid=3;
it should return 2 rows and
select * from orders where orderid=1;
should return 1 row.
Is it possible to achieve this. If yes, then how do I write my query.
Thanks in advance.with t as (
select 1 Orderid,1 noofbookstoorder from dual union all
select 2,3 from dual union all
select 3,2 from dual
select t.*
from t,
table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
where Orderid = <order-id>
/For example:
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
9 where Orderid = 2
10 /
ORDERID NOOFBOOKSTOORDER
2 3
2 3
2 3
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
9 where Orderid = 3
10 /
ORDERID NOOFBOOKSTOORDER
3 2
3 2
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
iNumberList))
9 where Orderid = 1
10 /
ORDERID NOOFBOOKSTOORDER
1 1
SQL> -- And if you want to select multiple orders
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
iNumberList))
9 where Orderid in (2,3)
10 /
ORDERID NOOFBOOKSTOORDER
2 3
2 3
2 3
3 2
3 2
SQL> SY.
Edited by: Solomon Yakobson on Oct 26, 2009 7:36 AM -
Selecting specific number of records
Hellow
How can we query certain number of records from table. For example if a table has thousands of records and i wish to query
1. first 500 records
2. Records between 500 and 1000 or between <anynumber> to <any number>
3. Records less than <some number>
I cannot perform the same operation from a primary key as it is not in serial.
I tried to use ROWNUM, but i cannot use this when i want to select rows less than 100 or rows between 100 and 200...
How can i accomplish this
Regards
Sunny1. first 500 records
select *
from ( YOUR_QUERY_GOES_HERE -- including the order by )
where rownum <= 500Another way using analytical functions can be found in the documentation Top N Ranking
2. Records between 500 and 1000 or between
<anynumber> to <any number>
select *
from ( select a.*, rownum rnum
from ( YOUR_QUERY_GOES_HERE -- including the order by ) a
where rownum <= MAX_ROWS )
where rnum >= MIN_ROWShttp://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:127412348064
3. Records less than <some number>
select *
from my_table
where my_column < <some number> -
Specific number of rows within field(s)
I'd like to get Top-N of Amt within Name&Loc as shown below.
Is there a way to reset either COUNT or ROWNUM to get this result?
Name---Loc--(ROWNUM)--Amt
James--abc--------1--1000
James--abc--------2---900
James--abc--------3---750
James--def--------1---500
James--def--------2---300
Jill---abc--------1---400
Jill---abc--------2---150
Jack---xyz--------1--2000
Jack---xyz--------2--1800
Thank you in advance for your help.try this,
select rownum as rank,ename,sal from ( select ename,sal from emp order by sal desc) where rownum<6
This query works on EMP table of SCOTT user.
If you change "desc" to "asc" it will start from lower to higher values. You can also play with the condition ( rownum < 6 ) to fetch ur desired no. of rows.
Hope this helps,
Kalpen.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Danielle:
Thanks for the reply, but that's not what I'm looking for.
Is there a way to get the Top-N (top 10,top20...)records within a group of fields (e.g. Name & Loc )?<HR></BLOCKQUOTE>
null -
Setting a specific number of rows visiable in a JTable
Hi there,
I am implementing the Master-Detail pattern by using a using a JSplitPane to devide a JPanel into two.
In the upper split-pane I show a JTable as the Master View.
In the lower split-pane I show a JTable as the Detail View.
My problem is that I just want to show 2 (two) rows and the Header in the Detail-View.
The default behavier is that my SplitPane shows 1 and a half row and the tableHeader.
How can I tell the SplitPane that I (only) want two rows and the Header ?table.setPreferredSize(...);Hi again,
thanks for input !
I tried your suggestion but it did not help me.
int rowHeight = detailCompareTable.getRowHeight();
Dimension headerSize = detailCompareTable.getTableHeader().getPreferredSize();
d = new Dimension ((int) d.getWidth(), (int) (2 * rowHeight + headerSize.getHeight()));
detailCompareTable.setPreferredSize(d);
masterDetailSplitPane.resetToPreferredSizes();What am I gettig wrong ? -
XMLIndex: finding indexed XPaths and the number of rows in the path table
Hi,
I am storing non-schema-based binary XMLs in an XMLType column in 11g (11.1.0.6.0) and would like to index the XMLs either partially or fully using XMLIndex. I'm expecting to have a large number (tens of millions) of XML documents and have some concerns about the size of the XMLIndex path table.
In short, I am worried that the path table might grow unmanageable large. In order to avoid this and to plan for table partitioning, I would like to create a report of all indexed XPaths in an XMLIndex and to find out how many times each path is actualized in the path table. I would do this for a representative XML sample.
I have been creating XMLIndexes with different exclude/include paths, gathering stats with DBMS_STATS (estimate_percent = 100) and selecting the number of rows in the path table through USER_TABLES.
If anyone knows a more straightforward way of doing this all advice is very much appreciated.
Best Regards,
Rasko LeinonenThanks Marco,
I managed to get out all indexed paths using the following SQL. It took a while to understand how the join the XDB.X$PT39CW6BJR8W4VVE0G0LLGA0OCR5 and XDB.X$QN39CW6BJR8W4VVE0G0LLGA0OCR5 tables together but got there in the end. This helps to clarify which XPaths are being currently indexed by the XMLIndex.
begin
for v_row in (select PATH from XDB.X$PT39CW6BJR8W4VVE0G0LLGA0OCR5)
loop
declare
v_i BINARY_INTEGER := 1;
v_id raw(8);
v_len BINARY_INTEGER := 2;
v_skip BINARY_INTEGER := 1;
begin
while v_i < utl_raw.length(v_row.path) and
v_i + v_len <= utl_raw.length(v_row.path)
loop
v_i := v_i + v_skip;
v_id := utl_raw.substr(v_row.path, v_i, v_len);
--dbms_output.put_line(v_id);
for v_row2 in (select LOCALNAME, flags from XDB.X$QN39CW6BJR8W4VVE0G0LLGA0OCR5
where ID = v_id )
loop
if rawtohex(v_row2.flags) = '01'
then
dbms_output.put('@');
end if;
dbms_output.put(v_row2.localname);
if v_i + v_len < utl_raw.length(v_row.path)
then
dbms_output.put('/');
end if;
end loop;
v_i := v_i + v_len;
end loop;
dbms_output.put_line('');
end;
end loop;
end;
Example output:
RUN
RUN/@accession
RUN/@alias
RUN/@instrument_model
RUN/@run_date
RUN/@run_center
RUN/@total_data_blocks
RUN/EXPERIMENT_REF
RUN/EXPERIMENT_REF/@accession
RUN/EXPERIMENT_REF/@refname
RUN/DATA_BLOCK
RUN/DATA_BLOCK/@name
RUN/DATA_BLOCK/@total_spots
RUN/DATA_BLOCK/@total_reads
RUN/DATA_BLOCK/@number_channels
RUN/DATA_BLOCK/@format_code
RUN/DATA_BLOCK/@sector
RUN/DATA_BLOCK/FILES
RUN/DATA_BLOCK/FILES/FILE
RUN/DATA_BLOCK/FILES/FILE/@filename
RUN/DATA_BLOCK/FILES/FILE/@filetype
RUN/RUN_ATTRIBUTES
RUN/RUN_ATTRIBUTES/RUN_ATTRIBUTE
RUN/RUN_ATTRIBUTES/RUN_ATTRIBUTE/TAG
RUN/RUN_ATTRIBUTES/RUN_ATTRIBUTE/VALUE -
JTextArea - set specific amount of rows, or characters...
I'm working on a Applet which handles text according to given parameters. One of these parameters sets a JTextArea to the horizontal size of, lets say: 5 rows. What i want is that once this TextArea is set to a specific number of rows no text beyond those rows can be inserted. 5 rows, or a specific amount of characters are allowed.
My problem is that the TextArea wont stop allowing text vertically. The TextArea is visibly set to 5 rows, which doesnt change. But how can i stop text from being inserted beyond row 5?
We have tried a number of different approaches, from trying to set TextArea's size with invisible scrollbars to overriding invalidate()...I never understand why people want to limit the number of rows in a JTextArea. Add the text area to a scroll pane and scroll bars will appear when the number of rows exceed the display area. The point of using a text area is to allow the user to enter data in a flexible format. If the format is not flexible then maybe you should be using another component or combination of combination of components.
Setting a maximum character size is valid if you intend to store the data on a database with a fixed size field. It is easy to do this by using a custom Document with you JTextArea. Read this section from the Swing tutorial on "General Rules for Using Text Components" for example code on how to do this:
http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
Note, if you really want to limit the text area to 5 lines then count the number of new line characters in the document and don't allow them to enter more than 4. -
How to select specific rows in rtf template for complex calculation
Hi,
I want custom calculation in my rtf template and for this i need to select specific cell's value OR specific row's value. Any one please suggest how can I get this. Below is the example i have plotted using excel. My target is to get field 8 and 9 using sum and minus. We can calculate column over column, is there any way to calculate row over row? If I use variables, then i have to create so many variables because I have more columns and rows to calculate (here i posted one sample table). Any one please help me how can I get expected result other than using variables! If "Using variables" is the only way then also give your valuable opinions.
Row No
Curr Qtr
PQtr1
PQtr2
3
B3
C3
D3
4
B4
C4
D4
5
B5
C5
D5
6
B6
C6
D6
7
B7
C7
D7
8
B8=SUM(B4:B7)
C8=SUM(C4:C7)
D8=SUM(D4:D7)
9
B9=B8-B5
C9=C8-C5
D9=D8-D5
Thanks.Hi AlexAnd,
Thanks for the reply, I got 0 using both codes. This is a dummy table and I plotted 3,4 to give an idea of row number (as like as excel). Rows are individual data sets combining different measures and dimensions with different values.
Account
Curr_Qtr
PQtr1
PQtr2
Deposit
10
15
20
Loan
15
20
25
Earning
20
25
30
Assets
25
30
35
Total
=SUM(15,20)
=SUM(20,25)
=SUM(25,30)
Expense
=SUM(15,20)-25
=SUM(20,25-30
=SUM(15,20)-25
Is there any way to identify the range or individual cell's value? Using variables I have to create lots of variables for each cells, I want to avoid that and want to use rows in calculation! Is that possible, Pls share your valuable opinions!
Thanks. -
How can I get a fixed number of rows on a SELECT?
I'm interested on get the last xx records of one specific query that returns an higher number of rows than xx. How can I do this?
you can use "where rownum < xx" if you
write "select * from (select ... from ... order by ...) where rownum < 10"
but you can't write "rownum > 10" because no record will be returned.
therefor you have to do like this:
select * from (select ..., rownum as nummer from (select ... from ... order by ...)) where nummer > 10
~
pascal -
Dear all,
I have a table containing 50 rows and I would like to select only rows between 20 and 30. Can you help me to do this with only one select statement or whatever you suggest. Also is it possible to do it without using rownum
Thanks
SLI do want want any specific criteriaSo in fact you should have called this thread Select unspecific rows, hmmm?
If you're really not bothered about the precise number of rows then the SAMPLE cause is a very performant way of getting a random subset of rows...
SQL> SET TIMING ON
SQL> SELECT count(*) FROM big_t
2 /
COUNT(*)
31764
Elapsed: 00:00:01.04
SQL> SELECT count(*) FROM
2 ( SELECT * FROM big_t SAMPLE (0.1) )
3 /
COUNT(*)
33
Elapsed: 00:00:00.03
SQL> SELECT count(*) FROM
2 ( SELECT * FROM big_t SAMPLE (0.1) )
3 /
COUNT(*)
32
Elapsed: 00:00:00.01
SQL> Cheers, APC -
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 control the number of rows selected from a sybase database table?
Hi, JDBC guru,
I'm working on project using Sybase 11.9.x database.We need to process a record in a table,first select it from the table,then do some computing,finally write it to a dbf file, if the above steps succeed,remove the original row in the table.Quite evidently, all these operation should be put into one transaction. But how can I select just a number of rows from the sybase database table?
Any hints?
Thank you in advance.
Regards,
JusitneStatement stmt...
stmt.setMaxRows(20);
Maybe you are looking for
-
10.3 Deploying same EAR on both admin server &managed :server jndi in use
Hypotehetical question but is it possible to deploy the same EAR file (some minor differneces) on both Admin server and not have an issue with jndi naming. I get the follwoing error when deploying on the managed server and suspect it could be cached
-
Organizing Photos in Folders or Albums
Hello I have hundreds of high res photos from a film project, and I'd like to organize them for easy viewing. As I understand the way iPhoto works, it is basically taking/referring to actual images from their original source. (like an external drive)
-
Bold text in linux... And formatting output in linux console
Hello everyone, I was wondering if there is a library of some sort that allows you to print text to the user but in bold or coloured or something like that? Thanks, Gary.
-
I had FF once before, now i want to install it again. After installing i got the message cannot acces page. error message UDB:1 How do i fix this?
-
I need to find my WEP key to connect to the internet on one of my ds games. It says to type in your IP address and it will take you to the site in which it will show you all the information. But when I type it in , nothing comes uo and they can't loc