Difference between revisions of "Import data"

From SQLZOO
Jump to: navigation, search
Line 31: Line 31:
 
COALESCE(phone, 'Not Available') AS phone, parkingSpace
 
COALESCE(phone, 'Not Available') AS phone, parkingSpace
 
FROM employeeParking LEFT OUTER JOIN
 
FROM employeeParking LEFT OUTER JOIN
employeeCopy ON (employeeParking.id = employeeCopy.id)</source>
+
employeeCopy ON (employeeParking.id = employeeCopy.id);
 +
SELECT * FROM mimic;</source>
 
<div class="ecomm e-mysql" style="display: none"></div>
 
<div class="ecomm e-mysql" style="display: none"></div>
 
</div>
 
</div>
  
 
{{Hacks Ref}}
 
{{Hacks Ref}}

Revision as of 16:32, 1 August 2012

Import someone else's data.

schema:scott
DROP TABLE employeeParking;
DROP TABLE employeeCopy;
DROP VIEW mimic;
 CREATE TABLE employeeParking(
  id TEXT,
  parkingSpace TEXT );
INSERT INTO employeeParking VALUES ('E01','F8');
INSERT INTO employeeParking VALUES ('E02','G22');
INSERT INTO employeeParking VALUES ('E03','F7');
CREATE TABLE employeeCopy (
  id TEXT,
  name VARCHAR(20),
  phone INTEGER );
INSERT INTO employeeCopy VALUES ('E01','Harpo',2753);
INSERT INTO employeeCopy VALUES ('E02','Zeppo',2754);
INSERT INTO employeeCopy VALUES ('E03','Groucho',2755);

To allow data to be imported into your system a mimic of your system can be made and then all that needs to be done is the rows from the old copy have to be deleted and then the table can be refilled with the fresh imported copy.

This method is not completely ideal but is efficient as a temporary measure until an up to date version of the table is made.

CREATE VIEW mimic AS
SELECT employeeParking.id, COALESCE(name, employeeParking.id) AS name,
COALESCE(phone, 'Not Available') AS phone, parkingSpace
FROM employeeParking LEFT OUTER JOIN
employeeCopy ON (employeeParking.id = employeeCopy.id);
SELECT * FROM mimic;
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense