Link to home
Start Free TrialLog in
Avatar of RobertNZana
RobertNZanaFlag for United States of America

asked on

How LIMIT MySql Query to top 10 rows - Error in SELECT clause: expression near '10'. Unable to parse query text.

Using latest versions of both ASP.NET and MySQL.  I want to create a query returning only the TOP 10 rows of data, but using LIMIT does not seem to work.  (This is a query within an XSD dataset.)

I've tried:
LIMIT 10
LIMIT 0,10
Putting the LIMIT after the WHERE and after the ORDER BY

The TableAdapter Query Configuration Wizard tells me:  Error in SELECT clause: expression near '10'. Unable to parse query text.

What am I missing?
SELECT     counties.County, states.UsStateAbbreviation, projects.ProjectId, projects.ProjectTitle
FROM         states INNER JOIN
                      counties ON states.StateId = counties.StateId INNER JOIN
                      projects ON counties.CountyId = projects.LocationCountyId
LIMIT 10
WHERE     (projects.IsVisible = 1) AND (projects.ReleaseDate <= CURDATE()) AND (projects.IsPrivate = 0)
ORDER BY projects.BidDateTime DESC

Open in new window

Avatar of Sharath S
Sharath S
Flag of United States of America image

Are you able to get all the records without LIMIT?  
SELECT     counties.County, states.UsStateAbbreviation, projects.ProjectId, projects.ProjectTitle
FROM         states INNER JOIN
                      counties ON states.StateId = counties.StateId INNER JOIN
                      projects ON counties.CountyId = projects.LocationCountyId
WHERE     (projects.IsVisible = 1) AND (projects.ReleaseDate <= CURDATE()) AND (projects.IsPrivate = 0)
ORDER BY projects.BidDateTime DESC

Open in new window

LIMIT has to be after the ORDER BY CLAUSE
>> Putting the LIMIT after the WHERE and after the ORDER BY
reb73 - yes, but i guess the asker tried that one also.
My mistake! Apologies.. (Thanks, Sharath!)
Avatar of RobertNZana

ASKER

Yes, I can get ALL records without the LIMIT.
SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried...

SELECT * FROM projects LIMIT 10

In my TableAdapter Query Configuration Wizard (in my XSD dataset) I get this error....

Error in FROM clause: near '10'. Unable to parse query text.

I am using MySql with Corelabs MyDirect.Net MySql stuff...


that means, your MySql does not support LIMIT. I don't know the reason. Can you give a try with TOP 10 like
SELECT TOP 10....
Yeah I tried that too, but it didn't work.  I've been googling and see that MySql works with LIMIT.  In fact, when I use my MySql Admin tool I can use LIMIT.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am using the connector from DevArt called MyDirect.Net.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial