1

I have the following query:

select count(*) FROM cumul AS t1, cumul AS t2 WHERE t1.id+1 = t2.id and t2.spec_datetime-t1.spec_datetime < 0.001 and t1.id < 100000 and t1.v1-t2.v1 = 0 and t1.v2-t2.v2 =0; 

I want to delete the same records with:

DELETE FROM cumul AS t1, cumul AS t2 WHERE t1.id+1 = t2.id and t2.spec_datetime-t1.spec_datetime < 0.001 and t1.v1-t2.v1 = 0 and t1.v2-t2.v2 = 0; 

I get:

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 'AS t1 , cumul AS t2 WHERE t1.id+1 = t2.id and t2.spec_datetime-t1.spec_datetime <' at line 1

How can I correct the query?

2 Answers 2

1
 DELETE t1 FROM cumul AS t1, cumul AS t2 ^^ Just add alias before FROM 

So try this:

DELETE t1 FROM cumul AS t1, cumul AS t2 WHERE t1.id+1 = t2.id and t2.spec_datetime-t1.spec_datetime < 0.001 and t1.v1-t2.v1 = 0 and t1.v2-t2.v2 = 0; 

Refer MySQL :: 13.2.2. DELETE Syntax for more information.

Sign up to request clarification or add additional context in comments.

Comments

0

You must specify which table in the table list to delete from (even though they're the same table in this instance):

DELETE t1 FROM cumul AS t1, cumul AS t2... 

http://dev.mysql.com/doc/refman/5.0/en/delete.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.