Download presentation
Presentation is loading. Please wait.
1
Rob Gleasure R.Gleasure@ucc.ie robgleasure.com
IS6126 Databases for Management Information Systems Lecture 2: Solution Rob Gleasure robgleasure.com
2
Exercise Consider the following problems related to the Customers database, what queries best solve them? We want to retrieve all customers with addresses in Mexico? SELECT * FROM Customers WHERE Country='Mexico'; We want to add a new Customer called 'Juan Garcia Ramos', with contact name 'Juan Ramos', address of 'Tribulete 4356', in the city 'México D.F', with a post code of '05029', in the country of 'Mexico‘? INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Juan Garcia Ramos', 'Juan Ramos','Tribulete 4356', 'México D.F','05029', 'Mexico'); We want to update that customer’s contact name to ‘Anna Ramos’? UPDATE Customers SET ContactName='Anna Ramos' WHERE CustomerName='Juan Garcia Ramos'; We want to delete the same customer? DELETE FROM Customers WHERE (CustomerName='Juan Garcia Ramos');
3
Exercise We want to select ProductName and CategoryID from the Products table, along with the SupplierName from the Suppliers table using a left join. Hint: use the SupplierID column in the Products table as a foreign key SELECT Products.ProductName, Products.CategoryID, Suppliers.SupplierName FROM Products LEFT JOIN Suppliers ON Products.SupplierID = Suppliers.SupplierID; We want to retrieve all cities mentioned in customer records and supplier records using a union SELECT City FROM Customers UNION SELECT City FROM Suppliers; We want create e new Customer_Cities_Backup table storing all cities listed in the Customers table SELECT City INTO Customer_Cities_Backup FROM Customers; We want to add all cities listed in the Suppliers table into the Customers table INSERT INTO Customers (City) SELECT City FROM Suppliers;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.