Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I receive the following error message:

"SELECT" is not valid at this position for this server version, expecting: '(', WITH

I am a total newbie at SQL. How do I resolve this error?

I put the exact same line at another PC with the exact same schema and it worked fine.

@danblack just tried that. Thanks for the advice.. Didn't work though.. :/ Any other ideas?? – Theo Bouras Nov 25, 2018 at 21:03 SQL Workbench is not very helpful with it's error messages. I found I had an error in my query but this error only points to the start of the query and not where the error lies. Thanks to your question and its answer, I was able to straighten it out – m1gp0z Jul 5, 2019 at 16:10

Have you tried to run the query deleting the space between "COUNT" and the bracket? I run a similar query to yours on MYSQL 5.7 and it gives me an error, but without that space the query runs.

Let's try this:

SELECT COUNT(DISTINCT first_name) FROM actor;
                @TheoBouras if this answer solved your problem you should mark it as the accepted answer. You might also want to upvote it by clicking the up arrow to the left of the answer.
– Wodin
                Nov 25, 2018 at 22:35
                Sometimes you get this error if you copy and paste query from few editor and chat messages
– Jeevan
                Apr 15, 2020 at 16:17
                Sometimes if you use a table name in some joins example  LEFT OUTER JOIN `Order` on `Order.ID`.......something  and in the where clause you use  Where Order.ID  without any back tick, this happens. As this was my issue.
– Parthan_akon
                Mar 6, 2021 at 11:02

I know this isn't the exact problem you stated, but this was the same error message I was getting. The message is so generic that it could be anything...

So, from one newbie to another:

For me, the error occurred when I nested one query within another. I had a ; at the end of the first query and forgot to take it out. That threw the error. Once I deleted the ; in the inner query and added one at the end of the new query the error resolved.

Error:

Select
From (....
    Select
    Where
    Group by
    Order ;     <== offending ;
) as ...
Where
Group by
Order

No Error:

Select
From (....
    Select
    Where
    Group by
    Order
) as ...
Where
Group by
Order ;   <== correct placement
                And here is another Newbie error.  I like separating my code into sections so I use as row of ---------------  but... in mySQL Workbench the comment has to be only 2 dashes like --  which means I get the same error unless I enter  -- <space> ------------.  Then it works.  (another 60 minutes I wish I could get back)
– Prashant Marathay
                Sep 25, 2019 at 18:56

Mine error resolved using 'db_name.' with table although I have already executed use 'db_name' command;

select * FROM db_name.table_name;
                How to achieve the same result without using db_name every time you'd like to query that specific DB? How to restrict the query only to a specific DB?
– Richard Topchii
                Jun 4, 2019 at 13:19
                Mine was similar, I was SELECTing specific columns from the table. I had to prepend table_name. to each of the column names, e.g. SELECT table_name.column_name from db_name.table_name
– Ollie
                Oct 19, 2020 at 4:04

I hope whenever you start writing select you will see this error. I too got the same error and read all the comments tried differently but nothing worked out for me but finally sorted out the error.

you got this error because you may not have closed the previous code. For example, if you have already written a code before, you ended up with order by (or) limit command but not closed it using a semicolon (;).

If you try to write a new command select after the previous command without closing it with a semicolon, you may end up with this error.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.