473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

LIMIT clause question

Hi,

I need to retrived a specific row from a query, these these specific
row number is the result of another query.

Is it possible to do that in one query with a subquery (mysql 4.1.x)?
Here is how I try (that gave me a syntax error.):

SELECT a FROM t1 WHERE a = 1 ORDER BY LIMIT (SELECT b FROM t2 WHERE c
= 2),1;

############
the 2 query standalone worked.

SELECT b FROM t2 WHERE c = 2; # return 3

So:
SELECT a FROM t1 WHERE a = 1 ORDER BY LIMIT 3,1; # return the good row
Any clue.
Thanks
Troy

Jul 20 '05 #1
2 1613
troy wrote:
I need to retrived a specific row from a query, these these specific
row number is the result of another query.

Is it possible to do that in one query with a subquery (mysql 4.1.x)?


See http://dev.mysql.com/doc/mysql/en/SELECT.html:
"LIMIT takes one or two numeric arguments, which must be integer constants."

I take that to mean that the arguments _cannot_ be expressions of any
type. So I don't think you can use a subquery in place of those
arguments, or any expression involving a field name from the
select-list, etc.

I think you're stuck using one query to fetch the row number value, and
then use that return value when building up the SQL string for the
second query.

Regards,
Bill K.
Jul 20 '05 #2
On Mon, 15 Nov 2004 14:56:42 -0800, Bill Karwin <bi**@karwin.com>
wrote:
troy wrote:
I need to retrived a specific row from a query, these these specific
row number is the result of another query.

Is it possible to do that in one query with a subquery (mysql 4.1.x)?


See http://dev.mysql.com/doc/mysql/en/SELECT.html:
"LIMIT takes one or two numeric arguments, which must be integer constants."

I take that to mean that the arguments _cannot_ be expressions of any
type. So I don't think you can use a subquery in place of those
arguments, or any expression involving a field name from the
select-list, etc.

I think you're stuck using one query to fetch the row number value, and
then use that return value when building up the SQL string for the
second query.

Regards,
Bill K.


I think you right, I will continue to use 2 distrincts queries.
Thanks
Troy
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tamer Higazi | last post by:
Hi! I have problems creating joins between tables and to limit rows for a specified clolumn. I have 2 tables! employees departments I face the problems with the GROUP BY clause and i don't...
10
by: Randell D. | last post by:
Folks, I have a SELECT that returns with multiple records - It works when I have a LIMIT clause but when I try to include a GROUP BY clause, the select returns nothing (ie no records, no...
1
by: Steve | last post by:
I've run in to a problem with a query I'm trying to write. I have attached a sample SQL script at the end of this post to show an overview of what I'm working with. I want to be able to use...
3
by: Jay K | last post by:
Hi, I have multiple queries like this: SELECT col1, col2, col3, col4 FROM table1, table2 where table1.col1 = table2.col1 and table1.col2 = 1 ORDER BY col3 desc LIMIT 5 and
5
by: Jeremy | last post by:
I am relatively inexperienced with SQL, and I am trying to learn how to analyze some data with it. I have a table with the following information. COMPANY ID , DATE, MarektValue I would like...
2
by: Urban | last post by:
hi, I have a question. Maybe You know the equivalent to command LIMIT from MySQL I couldn`t find something like this in MS SQL PS I try to display 10 records begining form e.g. 4 sort by id...
2
by: Mike | last post by:
New to PHP and MySQL. Using PHP5 and MySQL 4.1 Windows XP Pro IIS 5.1 I'm trying to page a recordset, and am using a LIMIT clause to fetch a defined range of records from my db. However, the...
1
by: lawrence k | last post by:
Want to replace the limit clause in a query, but can't get it right. What's wrong with this: $pattern = "(.*)limit (.*)"; $replacement = '$1'; $replacement .= "LIMIT $limit"; $replacement .=...
1
by: Franc Walter | last post by:
Hello, i didn't find it in the help, i think it is not possible, but i try to question anyway: Is the MySQL command "LIMIT" possible with a subquery in MySQL 4.0.27? e.g.: SELECT * FROM tab1...
1
by: henryrhenryr | last post by:
Hello! I'm having a bit of trouble with a query. I am trying to paginate a set of results using LIMIT. Each result has a bit of 'basic' data and potentially multiple 'additional' data. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.