Sign in to follow this  
Followers 0
felanor

MySQL Help

7 posts in this topic

Hi Everyone,

I have a very simple select statement, and I dont know why its giving me so many troubles. I am hoping someone here can provide some advice.

SELECT * FROM products ORDER BY name WHERE set = 3 LIMIT 0 , 20;

This here is the error.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE set = 3 LIMIT 0 , 20' at line 1

The strange part is, If I remove the "WHERE set = 3", the rest of the code runs perfectly, just as expected.

Am I making a simple mistake that I am just not seeing? I've confirmed the table 'products' has a field named 'set'. I've tried encompassing both the field name and the number of that field in quotes as well as the ` sign.

Thanks,

~Felanor

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try swapping the WHERE and ORDER BY phrases, like this:

CODE
SELECT * FROM products WHERE set = 3 ORDER BY name LIMIT 0 , 20;
Edited by dalisuit

Share this post


Link to post
Share on other sites

First, I agree with dalisuit, "ORDER BY" MUST come after "WHERE".

Second, what does this have to do with AutoIt?

Share this post


Link to post
Share on other sites

First, I agree with dalisuit, "ORDER BY" MUST come after "WHERE".

Second, what does this have to do with AutoIt?

@weaponx, it might have everything to do with AutoIt. There are AutoIt applications that access a MySQL or SQLite database.

See this post for an example of such.

http://www.autoitscript.com/forum/index.php?showtopic=73454

Share this post


Link to post
Share on other sites

@weaponx, it might have everything to do with AutoIt. There are AutoIt applications that access a MySQL or SQLite database.

See this post for an example of such.

http://www.autoitscript.com/forum/index.php?showtopic=73454

I know that. General Help & Support its for issues with AutoIt. No code was shown that uses AutoIt. Just because AutoIt can interface arbitrarily with an outside program doesn't mean we support said program.

Share this post


Link to post
Share on other sites

Hi Guys,

Thanks for all the help. It seems the version of MySQL I am running requires that the field for the WHERE clause be wrapped in the `` symbols. After putting those in and switching the ORDER BY with the WHERE, it worked perfectly.

Thanks again,

Felanor

@weaponx, I realize that the general help and support forum is typically used for help with AutoIt script, however, I didn't know where else to turn, as I have found that those who use the forum are extremely knowledgeable and are quick to respond. The SQL statment isn't for use in an AutoIt program, rather its being used in a PHP webpage. If it was wrong of me to ask that question here, I appologize for that now.

Share this post


Link to post
Share on other sites

It's okay. Just for future reference, non-AutoIt topics go to Chat.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0