Subject Re: [firebird-support] Create table from another table
Author Kurt Federspiel
Create the table with a primary key or index like:
CREATE TABLE suppliers AS (
id int not null,
address varchar(255) not null,
cat_type int,
PRIMARY KEY (id),
CONSTRAINT FK_suppliers_companies FOEIGN KEY
REFERENCES companies (id)
);

Then, insert into the table with an ORDER BY clause
like:

INSERT INTO suppliers (id, address, cat_type)
(SELECT companies.id, companies.address,
categories.cat_type
FROM companies, categories
WHERE companies.id = categories.id
AND companies.id > 1000
ORDER BY companies.id);

Hope this helps.
Kurt.



--- Alejandro Garcia <aleplgr@...> wrote:

> So? you create the table and then INSERT from a
> SELECT?
> If I do that I can't insert it ordered because the
> insert does not allow the ORDER BY in the INSERT
>
> Nick Upson <nick.upson@...> escribió:
> No it's not possible
>
> On 28/03/07, Alejandro Garcia wrote:
> > Is this the forum for simple/newbie SQL questions?
> >
> > Is it possible in InterBase 7.5 create a table
> from another table? I'm reading the specification of
> the CREATE satatement but can't find how
> > Like this:
> >
> > CREATE TABLE suppliers
> > AS (SELECT companies.id, companies.address,
> categories.cat_type
> > FROM companies, categories
> > WHERE companies.id = categories.id
> > AND companies.id > 1000);
> >
> >
> >
> > CREATE TABLE table [EXTERNAL [FILE] ' filespec']
> > ( [, | …]);
> > = col {< datatype> | COMPUTED [BY] (< expr>) |
> domain}
> > [DEFAULT { literal | NULL | USER}]
> > [NOT NULL]
> > [ ]
> > [COLLATE collation]
>
>
>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the
> Resources item
> on the main (top) menu. Try Knowledgebase and FAQ
> links !
>
> Also search the knowledgebases at
> http://www.ibphoenix.com
>
>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>
> ---------------------------------
>
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y móviles desde 1 céntimo por
> minuto.
> http://es.voice.yahoo.com
>
> [Non-text portions of this message have been
> removed]
>
>




____________________________________________________________________________________
Don't get soaked. Take a quick peek at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather