some time ago a big Excel file was imported into a PostgreSQL table. The layout in Excel was like this (see list numbers as row numbers):
- Some Column | Some other Column | Yet another one | ...
- Descriptiontext foo | Descriptiontext2 | bar foo bar | ...
- Value a | Value b | Value c | ...
- Value aa | Value bb | Value cc | ...
So there was the header row with the column names, then a row with a description text for each column and after that hundreds of rows with all the values.
In PostgreSQL two tables where created.
Table1:
CREATE TABLE t1 (
t1_id integer NOT NULL
col1 inet,
some_other_col character varying,
another_one integer,
...
);
Table2:
CREATE TABLE mapping (
mapping_id integer NOT NULL
colname character varying,
mapping character varying,
description character varying,
);
INSERT INTO mapping VALUES (1, 'col1', 'Some Column', 'Descriptiontext foo');
INSERT INTO mapping VALUES (2, 'some_other_col', 'Some other Column', 'Descriptiontext2');
INSERT INTO mapping VALUES (3, 'another_one', 'Yet another one', 'bar foo bar');
My question now is, how to merge these tables again to export an Excel sheet with the same format as the old one? And would I need PHP for that or is this possible using only SQL?
mapping
and display the first two rows (one loop over the results for each), and another one to fetch the rest of the data and display them as individual rows. – jcaron