If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > limit and found_Rows Equivalent functions in sybase

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-22-08, 08:58
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
limit and found_Rows Equivalent functions in sybase

Hi,
I am newbie to sybase. Can some one tell me Sybase equivalent functions for the following MYSQL functions

• limit
• found_rows
• SQL_CALC_FOUND_ROWS
Reply With Quote
  #2 (permalink)  
Old 04-23-08, 03:38
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
limit: set rowcount X, where X is the number of rows you want the limit set to.
found rows: select @@rowcount. returns the number of rows affected in the last query.

I don't know what SQL_CALC_FOUND_ROWS does, so I can;t help you with that one.
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #3 (permalink)  
Old 04-23-08, 04:56
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
thanks, martijnvs.

SQL_CALC_FOUND_ROWS does the following functionaliy :-

A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward:

mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
-> WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();

The second SELECT returns a number indicating how many rows the first SELECT would have returned had it been written without the LIMIT clause.

In the absence of the SQL_CALC_FOUND_ROWS option in the most recent SELECT statement, FOUND_ROWS() returns the number of rows in the result set returned by that statement.


is there any way in sybase with same functionality what SQL_CALC_FOUND_ROWS do..
Reply With Quote
  #4 (permalink)  
Old 04-23-08, 05:25
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
Hmm, I do not know of any function that does that.
Supposed you have this query: select id, name from mytable:
Code:
set rowcount 200
select id, name from mytable
set rowcount 0
will give 200 records (limit)
Code:
set rowcount 200
select id, name from mytable
select @@rowcount)
set rowcount 0
will give 200 records, plus the number 200, for the 200 records returned.

If you want to know how many records would have returned without the set rowcount-command, you could use this one:
Code:
select count(id) from mytable
This one only returnes the number of rows of that query. It is calculated on the server, so it should save you some time (the time it would take to send the resultset and display it on your client).
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #5 (permalink)  
Old 04-24-08, 01:58
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
Martijnvs, thank for the info..

but actually now i am doing porting. so i have to write a single query to limit the no of records. by using rowcount i have to send more than 1 query from my application. is there any smart way to do in a single query??
Reply With Quote
  #6 (permalink)  
Old 04-24-08, 04:08
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
Quote:
Originally Posted by mohanrao
Martijnvs, thank for the info..

but actually now i am doing porting. so i have to write a single query to limit the no of records. by using rowcount i have to send more than 1 query from my application. is there any smart way to do in a single query??
Why would you want to limit your resultset with something like 'limit'? If you want a specific, limited set of records, you can use a where-clause, but you can't specify an exact number of records as far as i know.

Can you post a sample of a query you want to port?
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #7 (permalink)  
Old 04-24-08, 06:34
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by Martijnvs
Why would you want to limit your resultset with something like 'limit'?
for the same reason that sybase developers use TOP

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 04-24-08, 06:44
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
select day(servlet_start_time) as DayOfMonth
from
sla
group by
day(servlet_start_time)
order by
$orderby$
limit
$startRow$, $numRows$

this is the query ...i am using this query for pagination..i am planning to use pagination support by database
Reply With Quote
  #9 (permalink)  
Old 04-24-08, 07:05
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
r937 , top is rocking but..if i want to get the rows from 15 to 20..like this..is there any some function..to do like this..i need this for paging
Reply With Quote
  #10 (permalink)  
Old 04-24-08, 07:15
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
i would just return all 31 days
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 04-28-08, 09:59
MattR MattR is offline
Registered User
 
Join Date: Mar 2001
Location: Lexington, KY
Posts: 606
Dude, Google "Sybase LIMIT" or "SQL SERVER LIMIT" and you'll see exactly how to do the offset in T-SQL. That would've taken far less time than posting this thread.
__________________
Thanks,

Matt
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On