Frage

I have 2 lists of postcodes, one origins and the other destinations:

Origins

  1. firstOrigin
  2. secondOrigin
  3. thirdOrigin

Destinations

  1. firstDestination
  2. secondDestination
  3. thirdDestination

I want to be able to import these to a mysql database so they are imported as single records for each journey. So the final results will be (where Origin and Destination are columns in the table):

Origin Destination

firstOrigin firstDestination


firstOrigin secondDestination


firstOrigin thirdDestination


secondOrigin firstDestination


secondOrigin secondDestination


secondOrigin thirdDestination


thirdOrigin firstDestination


thirdOrigin secondDestination


thirdOrigin thirdDestination


Apologies if this is unclear. It's difficult to display a table on here!

War es hilfreich?

Lösung

Follow this question for importing data from CSV to mysql. You have to have two tables origins and distinations or better yet create temporary tables origins and distinations. Once you have imported data in mysql, You can get your result by applying cross product on both tables like this

INSERT INTO yourResultingTable
    (origins, destinations)
    SELECT origins.origin, destination.destination FROM origins, destinations;

Andere Tipps

Try this :

INSERT INTO global_table (origin, destination)
SELECT origin_column, destination_column
FROM origin, destination
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top