Why phpStorm marks an error on valid query - mysql

I have a query:
$this->source->exec("UPDATE `account` AS `m1`,
(SELECT `m2`.`id`
FROM `account` AS `m2`
WHERE `m2`.`userid` = ? AND `m2`.`demo` = 0
ORDER BY `m2`.`date` DESC LIMIT 1) AS `m2`
SET `m1`.`default` = '1'
WHERE `m1`.`id` = `m2`.`id` AND `m1`.`demo` = 0", $user_id);
Now, phpStorm is trowing an error for the ORDER BY in the subquery. The query works perfectly when the code is run. I set MySQL as the SQL dialect in phpStorm.
The error is:
GROUP or HAVING expected, ORDER got.
How can I fix this error?

actually phpstorm recognize this symbol as invalid key when using with php, cz of php doesn't know aboutsql` use
If you check you sql with index.sql its show like this (without errors)
so just create test page with test.sql and copy your sql code.
then above of the code you can see orange color tab shows(check below image)
click Configure Data Source
and click MySQL in left side panel(below image)
and then click download in bottom of the panel(below image)
It will download file(s) relevant your versions
and click ok.
now delete the index.sql and you can use as same without error.
I have tested and work fine to me

Related

This query throws an error in one server and in another it doesn't

I was migrating an old app to a new hosting got a super weird error that looks like this.
This throws error in PHP MySQLi (Unknown column 't0.colx' in 'order clause'):
SELECT *
FROM (
SELECT colx, ...
FROM ...
) AS t0
ORDER BY t0.colx
This passes without problem:
SELECT *
FROM (
SELECT colx, ...
FROM ...
) AS t0
ORDER BY colx
Removing the t0 shows no error whatsoever.
In the old server I was using both works.
Anyone can point me out if I'm doing something wrong?
EDIT:
just to clarify, the error in being thrown by PHP's Mysqli not Mysql iself I think, if I copy paste the sql into phpmyadmin it throws no error and returns the data correctly. The error message I'm getting from mysqli object in mysqli->error property after I check if the mysqli->execute() returns false.
Versions:
PHP Version 5.5.38
Mysql 5.7.39
Removing "AS" didnt work.
The column named for "ORDER BY" its selected this way, maybe thats throwing the error? but on older hosting no error is shown.
SELECT
*
FROM
(
SELECT
...
if(numDoc IS NOT NULL, numDoc, CAST(numDocEx AS UNSIGNED)) AS numDoc,
...
) t0
ORDER BY t0.numDoc

Getting SQL Error: "SELECT" is not valid at this position for this server version, expecting '(' with

I have been trying out the following query in MySQL Workbench:
SELECT NAME,LEAD,OUTCOME,COUNT(*) AS NUMBER_OUTCOME
FROM OUTCOMES_BY_USER
ORDER by NAME,LEAD,OUTCOME ASC;
However I am getting this error:
"SELECT" is not valid at this position for this server version, expecting '(' with
I have tried to find out where the error is coming from by taking away parts of the query and seeing where it breaks, it seems to work when I try:
SELECT NAME
FROM OUTCOMES_BY_USER;
However when I add in another column (as shown below) I start getting the same error:
SELECT NAME, LEAD
FROM OUTCOMES_BY_USER;
I am really not sure how to get around this error, I was trying this query in sqlfiddle and it worked fine, however my sqlfiddle suddenly stopped working and the website just flat out wont build schemas for me anymore. so I tried it out on a my universities MySQL server and have been getting this error. Please help!
LEAD() is a MySQL function, hence it is a reserved word. You can add backticks around reserved table or column names to bypass this error :
SELECT NAME,`LEAD`,OUTCOME,COUNT(*) AS NUMBER_OUTCOME
FROM OUTCOMES_BY_USER
ORDER by NAME,`LEAD`,OUTCOME ASC;

SQL query valid in phpMyAdmin, but invalid in node.js using mysql package

I am trying to write a script that automatically downloads some items from a database in node.js, but am running into an error using the mysql package (latest version: 2.15). I have a query of the form:
SELECT `R1`, `R2`, `Flags` FROM `table` WHERE `Flags` = 'F1' OR `Flags` = 'F2'
This works just fine if I manually run this query through phpMyAdmin, but when I create and run the exact same query using node.js, I get the error Error: ER_OPERAND_COLUMNS: Operand should contain 1 column(s)
I've also tried using IN ('F1', 'F2'), but that doesn't work either. However, if I take out the items after the OR (so it just filters on one value), it works through node.js.
Is there something wrong with my query that's throwing these errors? Or is there another way to filter on multiple values that works for the mysql package?

PHPMyadmin #1066 - Not unique table/alias error only export

I'm actually having an issue with PHPMyAdmin :
I can execute my SQL query with nice result
I get an error when I'm trying to export the same query
Here's the query :
SELECT pn.nomenclature_id as nomenclature_id, pn.lettre as lettre, a.reference as reference_article, at.nom as nom_article
FROM item a, item_translation at, item_nomenclature an, item_nomenclature pn, item p
WHERE a.type = 1
AND a.id = at.id
AND at.lang = 'fr'
AND a.id = an.item_id
AND an.nomenclature_id = pn.nomenclature_id
AND pn.item_id = p.id
AND p.type = 2
AND p.marque_id = 2
Here's a video where I had the problem : https://youtu.be/Z5AAZhoX6W0
There's lot of thread on Not unique table/alias error but I didn't found any reason to explain why the query works in PHPMyAdmin "SQL" tab but not with export.
Thanks for your support,
David.
For anyone running into this same issue and not able to apply the fix mentioned in the github issue for whatever reason (I'm working on a VPS currently where I have no access to the phpMyAdmin install).
A simple workaround is to first create a view from your query result, then go to that view and export from there. Afterwards you can drop the view again.
(to create the view just run your query but click 'create view' instead of export, fill in a name and leave the rest as is; the view will become available in the left column under the node 'Views' instead of 'Tables')

No error message displayed on MYSQL Workbench latest version

I am running the latest version of MYSQL Workbench on a clean ubuntu 14.04 install, using the ubuntu package version.
When I run a valid query, it works fine, e.g.:
select * from users;
At the bottom of the window in what I would call the 'Status Bar' it says 'Executing Query...' for a few seconds while the query runs, and then changes to 'Query Completed' and displays the results.
So far so good.
If I then change the query to something invalid, e.g. :
select * from invalid_table;
The status bar says 'Executing Query...' and stays that way. I cannot see the error message reported anywhere.
If I run the same query in a terminal I get:
mysql> select * from invalid_table;
ERROR 1146 (42S02): Table 'mydb.invalid_table' doesn't exist
Surely the error message should show in workbench?
Am I missing something here?
The error is displayed within the Output History panel, at the bottom. It's possible your bottom panel is deactivated, or hidden. The linked documentation includes annotated screenshots and examples.
Did you hide the output panel?
View->panels -> show the output area
Or you may drag the output panelmini. You can move your mouse above the status bar , the mouse will turn to double arrow icon, then drag it and the output panel will show .