dbTalk Databases Forums  

Syntax of delete statement

comp.databases.mysql comp.databases.mysql


Discuss Syntax of delete statement in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
dn.perl@gmail.com
 
Posts: n/a

Default Syntax of delete statement - 03-05-2010 , 02:59 AM






I have two tables : t1(a1 integer) and t2(a1 integer).
I am trying a dlete statement which works in Oracle but not on MySql
server.

delete from t2 t where t.a1 in (select b.a1 from t1 b where b.a1
between 2 and 5) ;

What is wrong with the syntax of that statement ?

Reply With Quote
  #2  
Old   
Lennart
 
Posts: n/a

Default Re: Syntax of delete statement - 03-05-2010 , 05:28 AM






On 5 mar, 09:59, "dn.p... (AT) gmail (DOT) com" <dn.p... (AT) gmail (DOT) com> wrote:
Quote:
I have two tables : t1(a1 integer) and t2(a1 integer).
I am trying a dlete statement which works in Oracle but not on MySql
server.

delete *from t2 t *where *t.a1 in (select b.a1 from t1 b *where b..a1
between 2 and 5) ;

What is wrong with the syntax of that statement ?
AFAIK your query is valid, but MySQL does not support alias in delete
statements (at least I could not find any support for it in the
documentation). Try:

delete from t2 where t2.a1 in ( select b.a1 from t1 as b where b.a1
between 2 and 5 );

/Lennart

Reply With Quote
  #3  
Old   
Doug Miller
 
Posts: n/a

Default Re: Syntax of delete statement - 03-05-2010 , 06:38 AM



In article <ef52f90a-9b3c-46bd-b5c7-acfa84e077ba (AT) g7g2000yqe (DOT) googlegroups.com>, Lennart <erik.lennart.jonsson (AT) gmail (DOT) com> wrote:
Quote:
On 5 mar, 09:59, "dn.p... (AT) gmail (DOT) com" <dn.p... (AT) gmail (DOT) com> wrote:
I have two tables : t1(a1 integer) and t2(a1 integer).
I am trying a dlete statement which works in Oracle but not on MySql
server.

delete =A0from t2 t =A0where =A0t.a1 in (select b.a1 from t1 b =A0where b=
..a1
between 2 and 5) ;

What is wrong with the syntax of that statement ?

AFAIK your query is valid, but MySQL does not support alias in delete
statements (at least I could not find any support for it in the
documentation). Try:

delete from t2 where t2.a1 in ( select b.a1 from t1 as b where b.a1
between 2 and 5 );
Or, much more simply,

DELETE FROM t2 WHERE a1 BETWEEN 2 AND 5;

Reply With Quote
  #4  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: Syntax of delete statement - 03-05-2010 , 07:15 AM



Doug Miller wrote:
Quote:
In article <ef52f90a-9b3c-46bd-b5c7-acfa84e077ba (AT) g7g2000yqe (DOT) googlegroups.com>, Lennart <erik.lennart.jonsson (AT) gmail (DOT) com> wrote:
On 5 mar, 09:59, "dn.p... (AT) gmail (DOT) com" <dn.p... (AT) gmail (DOT) com> wrote:
I have two tables : t1(a1 integer) and t2(a1 integer).
I am trying a dlete statement which works in Oracle but not on MySql
server.

delete =A0from t2 t =A0where =A0t.a1 in (select b.a1 from t1 b =A0where b=
..a1
between 2 and 5) ;

What is wrong with the syntax of that statement ?
AFAIK your query is valid, but MySQL does not support alias in delete
statements (at least I could not find any support for it in the
documentation). Try:

delete from t2 where t2.a1 in ( select b.a1 from t1 as b where b.a1
between 2 and 5 );

Or, much more simply,

DELETE FROM t2 WHERE a1 BETWEEN 2 AND 5;

You're query will delete all rows in t2 where a1 is between 2 and 5.
The user only wants to delete the rows where a1 is between 2 and 5 AND
that value exists in t1.a1.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #5  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: Syntax of delete statement - 03-05-2010 , 07:16 AM



dn.perl (AT) gmail (DOT) com wrote:
Quote:
I have two tables : t1(a1 integer) and t2(a1 integer).
I am trying a dlete statement which works in Oracle but not on MySql
server.

delete from t2 t where t.a1 in (select b.a1 from t1 b where b.a1
between 2 and 5) ;

What is wrong with the syntax of that statement ?

Sorry, my crystal ball is in the shop and I can't see what error message
you get.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #6  
Old   
dn.perl@gmail.com
 
Posts: n/a

Default Re: Syntax of delete statement - 03-05-2010 , 07:44 AM



The MySql version is 4.0.26 ;
Each of the following command fails with Error 1064.
create table t1 (a1 integer) ;
create table t2 (a1 integer) ;


Command : delete from t2 where a1 in (select a1 from t1
where a1 between 2 and 5) ;
Message : 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 'select a1 from t1 where a1 between 2 and 5)' at line 1

Command : delete from t2 where a1 in (select b.a1 from t1 b
where b.a1 between 2 and 5) ; Or use t2.a1 instead of just
a1
..
..
Command : delete from t2 a where a.a1 in (select b.a1 from t1 b
where b.a1 between 2 and 5) ;
Now the error-message changes in its content.
Message : 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 'a where a.a1 in (select b.a1 from t1 b where b.a1 between

=====

Reply With Quote
  #7  
Old   
Doug Miller
 
Posts: n/a

Default Re: Syntax of delete statement - 03-05-2010 , 08:40 AM



In article <hmr05b$hpj$4 (AT) news (DOT) eternal-september.org>, Jerry Stuckle <jstucklex (AT) attglobal (DOT) net> wrote:
Quote:
Doug Miller wrote:
In article
ef52f90a-9b3c-46bd-b5c7-acfa84e077ba...oglegroups.com>, Lennart
erik.lennart.jonsson (AT) gmail (DOT) com> wrote:
On 5 mar, 09:59, "dn.p... (AT) gmail (DOT) com" <dn.p... (AT) gmail (DOT) com> wrote:
I have two tables : t1(a1 integer) and t2(a1 integer).
I am trying a dlete statement which works in Oracle but not on MySql
server.

delete =A0from t2 t =A0where =A0t.a1 in (select b.a1 from t1 b =A0where b=
..a1
between 2 and 5) ;

What is wrong with the syntax of that statement ?
AFAIK your query is valid, but MySQL does not support alias in delete
statements (at least I could not find any support for it in the
documentation). Try:

delete from t2 where t2.a1 in ( select b.a1 from t1 as b where b.a1
between 2 and 5 );

Or, much more simply,

DELETE FROM t2 WHERE a1 BETWEEN 2 AND 5;


You're query will delete all rows in t2 where a1 is between 2 and 5.
The user only wants to delete the rows where a1 is between 2 and 5 AND
that value exists in t1.a1.

Yes, you're right. I missed that first time through.

Reply With Quote
  #8  
Old   
Axel Schwenke
 
Posts: n/a

Default Re: Syntax of delete statement - 03-05-2010 , 09:32 AM



"dn.perl (AT) gmail (DOT) com" <dn.perl (AT) gmail (DOT) com> wrote:
Quote:
The MySql version is 4.0.26 ;
And your computer is a 386?

Subqueries were added to MySQL in the 4.1 series.
Currently "recommended for production" is 5.1.


XL

Reply With Quote
  #9  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: Syntax of delete statement - 03-10-2010 , 07:12 AM



On 5 Mar, 13:44, "dn.p... (AT) gmail (DOT) com" <dn.p... (AT) gmail (DOT) com> wrote:
Quote:
The MySql version is 4.0.26 ;
Each of the following command fails with Error 1064.
create table t1 (a1 integer) ;
create table t2 (a1 integer) ;

Command : delete *from t2 * where *a1 in (select a1 from t1
* * * * where a1 between 2 and 5) ;
Message : 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 'select a1 from t1 * where a1 between 2 and 5)' at line 1

Command : delete *from t2 * where *a1 in (select b.a1 from t1 b
* * * * where b.a1 between 2 and 5) ; * Or use t2.a1 instead ofjust
a1
.
.
Command : delete *from t2 a *where *a.a1 in (select b.a1 from t1 b
* * * * where b.a1 between 2 and 5) ;
Now the error-message changes in its content.
Message : 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 'a *where *a.a1 in (select b.a1 from t1 b * where b.a1 between

=====
This should be done with a NOT NULL test on a LEFT JOIN

Reply With Quote
  #10  
Old   
Lennart
 
Posts: n/a

Default Re: Syntax of delete statement - 03-10-2010 , 07:45 AM



On 10 mar, 14:12, Captain Paralytic <paul_laut... (AT) yahoo (DOT) com> wrote:
Quote:
On 5 Mar, 13:44, "dn.p... (AT) gmail (DOT) com" <dn.p... (AT) gmail (DOT) com> wrote:



The MySql version is 4.0.26 ;
Each of the following command fails with Error 1064.
create table t1 (a1 integer) ;
create table t2 (a1 integer) ;

Command : delete *from t2 * where *a1 in (select a1 from t1
* * * * where a1 between 2 and 5) ;
Message : 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 'select a1 from t1 * where a1 between 2 and 5)' at line 1

Command : delete *from t2 * where *a1 in (select b.a1 from t1 b
* * * * where b.a1 between 2 and 5) ; * Or use t2.a1 instead of just
a1
.
.
Command : delete *from t2 a *where *a.a1 in (select b.a1 from t1 b
* * * * where b.a1 between 2 and 5) ;
Now the error-message changes in its content.
Message : 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 'a *where *a.a1 in (select b.a1 from t1 b * where b.a1 between

=====

This should be done with a NOT NULL test on a LEFT JOIN
I'm not sure I understand, can you provide an example?

/Lennart

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.