mysql subquery error can not be identified. error code 1064 - mysql

what is the error in below mysql query?
SELECT distinct d.temp,d.pre FROM Data as d
WHERE NOT EXISTS
(
SELECT distinct d1.temp,d1.pre FROM Data as d1 where
d1.temp <=d.temp AND d1.pre <>d.pre
AND (d1.temp < d.temp or d1.pre<d.pre)
)

As per your SQL Fiddle your query executes fine.

Related

Delete Query in MySQL 5.7 not working because error SQL Error [1093] shown

I tried to see other similar problems and i've done the same as other people but my delete clause is not working.
DELETE gl FROM int_id2_game_server.game_link gl
WHERE gl.game_pack_id = 794 AND gl.id NOT IN (
SELECT * FROM (SELECT parent_id FROM int_id2_game_server.game_link
WHERE gl2.game_pack_id = 794 AND gl2.parent_id IS NOT NULL)gltemp);
Error shown as SQL Error [1093] [HY000]: You can't specify target table 'gl' for update in FROM clause
Which modification I have to do?

Invalid argument to function error in ms access in correlated subquery

I have a problem in my correlated subquery in ms access.
Here is my query :
SELECT t1.MfgProductId,
(SELECT Sum(BalanceQuantity)
FROM qry_MfgShipmentDetailWIP AS t2
WHERE t2.MfgProductId = t1.MfgProductId) AS PrevQty
FROM qry_MfgShipmentDetailWIP AS t1;
But when i run this i get error : invalid argument to a function.
But when i run like this :
SELECT t1.MfgProductId,
(SELECT Sum(BalanceQuantity)
FROM qry_MfgShipmentDetailWIP AS t2
WHERE t2.MfgProductId = 'CFC1C06') AS PrevQty
FROM qry_MfgShipmentDetailWIP AS t1;
It runs fine.
Please help what causes the error?
Error while running the query in ms access sql view:

Delete duplicates for multiple columns in JOIN on same table

I am trying to make a delete from joined same table like this:
DELETE FROM `sp10_seo_url` AS sp1 JOIN
(
SELECT seo_url_pk, COUNT(*) AS maxc
FROM `sp10_seo_url`
GROUP BY seo_url_entity_type, seo_url_entity_id, seo_url_language_fk
HAVING maxc > 1
) AS sp2
ON sp1.seo_url_pk = sp2.seo_url_pk
However I am getting a mysql 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 'AS sp1 JOIN ( SELECT seo_url_pk, COUNT(*) AS maxc FROM `sp10_s' at line 1
And I am not sure at all where the error is. The inner query runs just fine and returns the expected set of results. The "ON" keys are properly named (same since we are talking about the same table).
I guess the idea of the query is pretty clear (clean the table of different rows have the same set of values for the three "group by" columns. Is there another way to do this?
Thanks!
you can "cheat" mysql with a double indirection (as explained here Deleting a row based on the max value):
delete from `sp10_seo_url`
where seo_url_pk in (
select seo_url_pk from (
SELECT seo_url_pk
FROM `sp10_seo_url` sp1,
(
SELECT seo_url_entity_type, seo_url_entity_id, seo_url_language_fk
FROM `sp10_seo_url`
GROUP BY seo_url_entity_type, seo_url_entity_id, seo_url_language_fk
HAVING count(*) > 1
) sp2
where sp1.seo_url_entity_type = sp2.seo_url_entity_type
and sp1.seo_url_entity_id = sp2.seo_url_entity_id
and sp1.seo_url_language_fk = sp2.seo_url_language_fk
) t
);
http://sqlfiddle.com/#!2/899ff5/1

Running EXPLAIN on MySQL query is giving a syntax error

I have a basic query that looks like the following that's running slow, so I'm trying to figure out where there's missing indexes or other optimizations I can make:
drop table weights;
CREATE TABLE weights engine=myisam
SELECT 'K' AS STAT,
z.WEIGHT,
COUNT(*) AS SAMPLE,
round(AVG(z.FINAL_2Y),15) AS 2Y,
round(AVG(z.FINAL_3Y),15) AS 3Y,
round(AVG(z.FINAL_4Y),15) AS 4Y,
round(AVG(z.FINAL_5Y),15) AS 5Y,
round(AVG(z.FINAL_6Y),15) AS 6Y
FROM
( SELECT /* insert big query here */ ) z
GROUP BY WEIGHT;
This query is running awfully slow so I'm trying to make one simple change with the following:
drop table sp_weights_holding_table
CREATE TABLE sp_weights_holding_table engine=myisam
EXPLAIN SELECT 'K' AS STAT,
z.WEIGHT,
COUNT(*) AS SAMPLE,
round(AVG(z.FINAL_2Y),15) AS 2Y,
round(AVG(z.FINAL_3Y),15) AS 3Y,
round(AVG(z.FINAL_4Y),15) AS 4Y,
round(AVG(z.FINAL_5Y),15) AS 5Y,
round(AVG(z.FINAL_6Y),15) AS 6Y
FROM
( SELECT /* insert big query here */ ) z
GROUP BY WEIGHT;
As soon as I pop the EXPLAIN in, I get a syntax error. I'm using MySQL 5.6.13 on Amazon RDS. The error looks like the following:
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 'EXPLAIN SELECT 'K' AS STAT,
z.WEIGHT,
COUNT(*) AS SAMPLE,
r' at line 2
You must semicolon the end of the sql command.
Change to
drop table sp_weights_holding_table;
CREATE TABLE sp_weights_holding_table engine=myisam;
EXPLAIN SELECT 'K' AS STAT,
....
Use the EXPLAIN with the SELECT query alone without the first two lines for dropping/creating the table:
EXPLAIN SELECT 'K' AS STAT,
z.WEIGHT,
COUNT(*) AS SAMPLE,
round(AVG(z.FINAL_2Y),15) AS 2Y,
round(AVG(z.FINAL_3Y),15) AS 3Y,
round(AVG(z.FINAL_4Y),15) AS 4Y,
round(AVG(z.FINAL_5Y),15) AS 5Y,
round(AVG(z.FINAL_6Y),15) AS 6Y
FROM
( SELECT /* insert big query here */ ) z
GROUP BY WEIGHT;

Issue in MySQL stored procedure from 5.0 to 5.1

When I upgraded from MySQL 5.0 to 5.1, the following SQL statement in an SP stopped working with error code 1064 - invalid column name VARCLNO in WHERE clause:
SELECT *, CLNO as VARCLNO, concat(CLCompany, CLSurname, CLFirstName, CLNO) as CLSort FROM Customer WHERE
CLEditDate = (select max(CLEditDate) from Customer WHERE VARCLNO = CLNO )
ORDER BY CLSort;
The CUSTOMER table columns all begin CL.
Any help much appreciated.
Try this query using table alias:
SELECT *,
CLNO as VARCLNO,
concat(CLCompany, CLSurname, CLFirstName, CLNO) as CLSort
FROM Customer AS T1
WHERE
CLEditDate = (select max(CLEditDate) from Customer WHERE T1.CLNO = CLNO )
ORDER BY CLSort;