472,342 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

MySQL Multi Table Delete

I have 2 tables t and t1. In this case, t1 is a copy of t. I want to
delete rows from t1 based on criteria on the t table and a relationship
between t ad t1 (in this case the id column). In the results below, I
would think that the delete should have deleted row 1 {1 5 me) and not
row 3 (1 5 they) when I run this statement

delete t1 from t, t1 where t.id = t1.id and t.id=1 and t.name = 'me';

Any ideas on why row 2 is deleted?

Same results on Your MySQL connection id is 38495 to server version:
4.0.10-gamma-nt Windows 2000
or Your MySQL connection id is 221 to server version:
4.0.13-Max Linux 8.0

This is the contents of t & t1 to start
mysql> select * from t1;
+------+------+------+
| id | no | name |
+------+------+------+
| 1 | 5 | me |
| 2 | 7 | you |
| 1 | 5 | they |
| 2 | 5 | me |
| 3 | 7 | you |
| 3 | 7 | they |
| 3 | 5 | we |
+------+------+------+
7 rows in set (0.00 sec)

This is the delete statement

mysql> delete t1 from t, t1 where t.id = t1.id and t.id=1 and
t.name = 'me';
Query OK, 2 rows affected (0.00 sec)

This is the result
mysql> select * from t1;
+------+------+------+
| id | no | name |
+------+------+------+
| 2 | 7 | you |
| 2 | 5 | me |
| 3 | 7 | you |
| 3 | 7 | they |
| 3 | 5 | we |
+------+------+------+
5 rows in set (0.01 sec)

mysql> show create table t;
+-------+---------------------------------------------------------------
------------------------------------------------------------+
| Table | Create Table
|
+-------+---------------------------------------------------------------
------------------------------------------------------------+
| t | CREATE TABLE `t` (
`id` int(11) default NULL,
`no` int(11) default NULL,
`name` char(20) default NULL
) TYPE=MyISAM |
+-------+---------------------------------------------------------------
------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show create table t1;
+-------+---------------------------------------------------------------
-------------------------------------------------------------+
| Table | Create Table
|
+-------+---------------------------------------------------------------
-------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int(11) default NULL,
`no` int(11) default NULL,
`name` char(20) default NULL
) TYPE=MyISAM |
+-------+---------------------------------------------------------------
-------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> truncate t1;
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 select * from t;
Query OK, 7 rows affected (0.01 sec)
Records: 7 Duplicates: 0 Warnings: 0

mysql> select * from t1;
+------+------+------+
| id | no | name |
+------+------+------+
| 1 | 5 | me |
| 2 | 7 | you |
| 1 | 5 | they |
| 2 | 5 | me |
| 3 | 7 | you |
| 3 | 7 | they |
| 3 | 5 | we |
+------+------+------+
7 rows in set (0.00 sec)

mysql> delete t1 from t, t1 where t.id = t1.id and t.id=1 and t.name =
'me';
Query OK, 2 rows affected (0.00 sec)

mysql> select * from t1;
+------+------+------+
| id | no | name |
+------+------+------+
| 2 | 7 | you |
| 2 | 5 | me |
| 3 | 7 | you |
| 3 | 7 | they |
| 3 | 5 | we |
+------+------+------+
5 rows in set (0.01 sec)

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
0 6324

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: el_roachmeister | last post by:
I have been using flat files for a while but thought I should learn mysql. There are two things I dont like about mysql compared to using...
5
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i...
0
by: Vic | last post by:
Hi all, When I test the Delete multi table function in MySQL, DELETE table_name ...] FROM table-references I accidentally delete all data...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated:...
2
by: TomyB | last post by:
Here's on for you, any help would be greatly appreaciated as it is sending me mad... I have three tables tbl_photo, tbl_photo_gallery and...
3
by: saracen44 | last post by:
Hi I have MyISAM tables When I'm deleting parent I want to delete children in the same time. How can I do It? What are possibilities? ...
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary...
0
by: Bucker | last post by:
Could someone view the following that I copied from phpMyAdmin and tell me from the statistics if are server is running OK? Does it look like we...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.