Using a column as a limit... possible?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Using a column as a limit... possible?

Post by someberry »

Very quick question which doesn't appear to work, but thought I would throw it open to people more clever that me.

I have tried the following, both of which end up with a syntax error. Seems MySQL is expecting a number and nothing else.

Code: Select all

SELECT field_1, field_2
FROM my_table
LIMIT field_3

Code: Select all

SELECT field_1, field_2, (@limit:=(field_3))
FROM my_table
LIMIT @limit
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Using a column as a limit... possible?

Post by John Cartwright »

Unfortunately, no. Mysql required a constant to be used in the LIMIT clause.
Post Reply