Join multiple tables
Posted in 1994
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL, Triggers, Constraints & Referential Integrity, Cloud, Docker & Containers
To set the record I am using On-Line and ISQL with perform and ace for
updating tables and reporting. My problem is getting data from multiple
tables by doing a query on one and then joining with others using data
from the first. I need to be able to do this both with forms and reports.
Part of the problem is that I am trying to go backwards from the way the
db is actually designed.
Example:
Three tables-
container - this table contains one entry for each
container in the system. Unique Key container ID.
This table is updated using forms both as a single
table update, updates of other tables, and
automatically from a third party SQLserver.
history - this table contains the same columns as the
container table but does not have a unique key.
ie-it can have multiple entries for the same
container. A row is added to this table using a
trigger that is executed when a column,
dumped_date is updated.
manifest - this table is as the name indicates, a table
that contains information about a shipment -
including the ID of one(1) to four(4)
containers included in the shipment. This table
has a unique key which is the manifest ID. The
form used to enter this data changes tables and
updates the container table.
My problem is that I would like to be able to enter a mainifest ID and
then combine data from the manifest, container, and history tables to make
a report or update a column in the correct row of the container or history
tables. I have tried several things with limited success.
Example:
In ACE report entering mani_id
select manifest.manifest_id, cont1_id, cont2_id, cont3_id,
cont4_id, container_id
from manifest, container
where manifest.manifest_id = $mani_id
and cont1_id = container_id
and container.manifest_id = $mani_id
This works fine for the first container but when I add -
or cont2_id = container_id
and container.manifest_id = $mani_id
I get every container in the container table in my report. Also using the
history table in the scheme of things causes even more problems. I have
also tried using a query only on the manifest and a sub query in the where
section with basically the same results. Can't see how a UNION claues
would help.
The example is for only the ACE report but I need to do same type of
select in a form to set indicators in the correct container and/or history
tables.
Any suggestions anyone??? At this point we do not have ESQL-C but will
some time after the first of the year. In the mean time I need to use
what I have.
-------------------- ***** JBT ***** ------------------
J. B. Taylor (jbtaylor@lanmail.rmc.com)
Reynolds Metals Company
Manufacturing Technology Laboratory
3326 East 2nd Street
Muscle Shoals, AL 35661-1258
FAX: 205-386-9656
Voice: 205-386-9658
-------------------------------------------------------