Subject RE: [firebird-support] Converting FireBird Table from horizontal to vertical
Author Dunbar, Norman
Morning Sean,

>> What you want to do is create a single SELECT which uses the
>> UNION to create a single set of rows to be inserted into the
>> new table.
I think this should be a UNION ALL because if, for example, one of the
features for a specific ID is the same value as another feature for that
ID, then you will only get one of them. You need the union all to get
all of them.

SQL> create table x (
CON> id integer,
CON> feature integer,
CON> feature1 integer,
CON> feature2 integer);
SQL> commit;

SQL> insert into x values (1,1,1,1);
SQL> insert into x values (2,2,NULL,NULL);
SQL> commit;

SQL> select id, feature from x where feature is not null
CON> UNION
CON> select id, feature1 ........;

ID FEATURE
============ ============
1 1
2 2

Repeat with UNION ALL:

ID FEATURE
============ ============
1 1
2 2
1 1
1 1

Looks like it needs an ORDER BY on the UNION ALL as well, if we do need
the rows in ID order.


Cheers,
Norman.



Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.

We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.

If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk