Using the 'from join delete' Alternative to Delete Data : Delete « Insert Delete Update « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Insert Delete Update » Delete 
Using the 'from join delete' Alternative to Delete Data
    
Drop table DVDs;
Drop table Studios;


CREATE TABLE DVDs
(
   DVDID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
   DVDName VARCHAR(60NOT NULL,
   NumDisks TINYINT NOT NULL DEFAULT 1,
   YearRlsd YEAR NOT NULL,
   StudID VARCHAR(4NOT NULL
ENGINE=INNODB;


CREATE TABLE Studios
(
   StudID VARCHAR(4NOT NULL,
   StudDescrip VARCHAR(40NOT NULL,
   PRIMARY KEY (StudID)
)
ENGINE=INNODB;

INSERT INTO Studios VALUES ('s101', 'Universal Studios'),
                           ('s102', 'Warner Brothers'),
                           ('s103', 'Time Warner'),
                           ('s104', 'Columbia Pictures'),
                           ('s105', 'Paramount Pictures'),
                           ('s106', 'Twentieth Century Fox'),
                           ('s107', 'Merchant Ivory Production');


INSERT INTO DVDs 
(DVDName, NumDisks, YearRlsd, StudID)
VALUES 
     ('Christmas', 12000's105'),
     ('What',      12001's103'),
     ('Out',       12000's101'),
     ('Falcon',    12000's103'),
     ('Amadeus',   11997's103'),
     ('Show',      22000's106'),
     ('View',      12000's107'),
     ('Mash',      22001's106');


select from DVDs;

DELETE DVDs
FROM DVDs, Studios
WHERE DVDs.StudID=Studios.StudID
   AND Studios.StudDescrip='New Line Cinema';


select from DVDs;

           
         
    
    
    
  
Related examples in the same category
1.Deleting Rows with DELETE
2.Using DELETE LOW_PRIORITY command
3.Delete by JOIN
4.Delete with JOIN 2
5.Delete row with condition
6.Delete statement with subquery (ERROR 1093 (HY000): You can't specify target table 'EmployeeS' for update in FROM clause)
7.DELETE statement using the alternative.
8.Joining Tables in a DELETE Statement
9.Delete with where clause
10.Delete ignore
11.Adding Subqueries to Your DELETE Statements
12.Delete All Threads Except the Last 500
13.Delete rows from multiple tables
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.