Subject | How to do a union? |
---|---|
Author | Gerhardus Geldenhuis |
Post date | 2001-11-21T14:00:35Z |
Hi have two tables:
CREATE TABLE REPLICATION_LOG
(
LOGID DOM_INCFIELD NOT NULL,
LOGTIMESTAMP DOM_TIMESTAMP,
TABLENAME DOM_VARCHAR25 NOT NULL,
UID DOM_VARCHAR25 NOT NULL,
DBACTION DOM_VARCHAR25 NOT NULL,
BRANCH DOM_VARCHAR25 NOT NULL,
REPLICATED DOM_BOOLEAN,
DATEREPLICATED DATE,
CONSTRAINT PK_REPLICATION_LOG PRIMARY KEY (LOGID)
)
CREATE TABLE REPLICATION_ORDER
(
TABLENAME DOM_VARCHAR25 NOT NULL,
WEIGHT INTEGER NOT NULL,
CONSTRAINT PK_REPLICATION_ORDER PRIMARY KEY (TABLENAME, WEIGHT)
)
I want to do the following select from replication_log:
"select distinct(tablename) from replication_log"
then I want to do a union between that selection and
replication_order and sort by weight. This is to achieve
a specific order of sorting for the replication. I think
this is the best way to do this.
How do I do this. I have never used union before and the embedded-sql
guide did not explain it in a understandable way. It assumes some
basic knowledge which I learn as I go.
Any help appreciated.
Groete
Gerhardus
PS
I should realy buy myself a SQL book. :-))
CREATE TABLE REPLICATION_LOG
(
LOGID DOM_INCFIELD NOT NULL,
LOGTIMESTAMP DOM_TIMESTAMP,
TABLENAME DOM_VARCHAR25 NOT NULL,
UID DOM_VARCHAR25 NOT NULL,
DBACTION DOM_VARCHAR25 NOT NULL,
BRANCH DOM_VARCHAR25 NOT NULL,
REPLICATED DOM_BOOLEAN,
DATEREPLICATED DATE,
CONSTRAINT PK_REPLICATION_LOG PRIMARY KEY (LOGID)
)
CREATE TABLE REPLICATION_ORDER
(
TABLENAME DOM_VARCHAR25 NOT NULL,
WEIGHT INTEGER NOT NULL,
CONSTRAINT PK_REPLICATION_ORDER PRIMARY KEY (TABLENAME, WEIGHT)
)
I want to do the following select from replication_log:
"select distinct(tablename) from replication_log"
then I want to do a union between that selection and
replication_order and sort by weight. This is to achieve
a specific order of sorting for the replication. I think
this is the best way to do this.
How do I do this. I have never used union before and the embedded-sql
guide did not explain it in a understandable way. It assumes some
basic knowledge which I learn as I go.
Any help appreciated.
Groete
Gerhardus
PS
I should realy buy myself a SQL book. :-))