diff --git a/BasesDeDatos/resumen1.org b/BasesDeDatos/resumen1.org index 3c54b78..4d99785 100644 --- a/BasesDeDatos/resumen1.org +++ b/BasesDeDatos/resumen1.org @@ -43,3 +43,41 @@ FROM ( ) AS d GROUP BY d.DepartamentoId; #+end_src + +* clase3 Subconsulta con update, insert, delete + +** insert +#+begin_src sql +INSERT INTO Customers + (CustomerID, + CompanyName, + ContactName, + ContactTitle, + Address, City, Region, PostalCode, Country, Phone, Fax) +SELECT + SUBSTRING(firstname, 1, 3) + SUBSTRING(lastname, 1, 2) AS CustomerID, + lastname AS CompanyName, + firstname AS ContactName, + title AS ContactTitle, + address, city, region, postalcode, country, homephone AS Phone, NULL AS Fax +FROM Employees; +#+end_src +** update +#+begin_src sql +DELETE FROM [Order Details] +WHERE OrderID IN ( + SELECT OrderID + FROM Orders + WHERE OrderDate = '2005-04-14' +); +#+end_src +** delete +#+begin_src sql +UPDATE Products +SET UnitPrice = UnitPrice + 2 +WHERE SupplierID IN ( + SELECT SupplierID + FROM Suppliers + WHERE Country = 'USA' +); +#+end_src