A query on the recipesexample database from SQL for mere mortals

What’s the problem with this query?
It’s only a slight modification from the SQL for mere mortals book…

Select r.RecipeTitle, 
from (Select RecipeClassID
      from recipe_classes as RC
      where RC.RecipeClassDescription like "Main%" 
            or RC.RecipeClassDescription="Dessert") as rcfiltered
inner join recipes as r
on rcfiltered.RecipeClassID = r.RecipeClassID;

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Remove the comma:

Select recipes.RecipeTitle, 
from ...

There must be no comma following the last expression in the select-list.

WRONG:

SELECT A, B, C, FROM ...

RIGHT:

SELECT A, B, C FROM ...

With the extra comma, the query produces this error in MySQL:

ERROR 1064 (42000): 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 ‘from (Select RecipeClassID
from recipe_classes as RC
where RC.Recipe’ at line 2

Here’s a tip on how to read syntax error messages: It tells you exactly where the parser got confused: "near 'from ..." This probably means something you wrote in the query immediately prior to that position was wrong. Knowing this helps to narrow down the cause of the syntax error.

If the error says, "near ''" then it means it got to the end of the query and then got confused. Maybe you opened a parenthesis but forgot to close it for example.

That’s the first problem that jumps out at me. I don’t know the original query you were modifying, so I don’t know how you changed it. I don’t know if the query does what you intend it to do, but aside from the comma issue it looks like the syntax is valid.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x