The
final step before adding the JOIN statement to the query is to add in a
statement for including the ZNAME since this is the column that contains the
attachment filename desired in the final output. This is accomplished the same
as in prior examples where the column name is included after the SELECT
statement.
Ex:
ZNAME AS “Attachment Filename”
To
add the JOIN statement, you must include:
1)
The table you want to JOIN
2)
and the column from that table that matches a column in the existing table.
In
the example:
JOIN
ZATTACHMENT (the new table being added)
on
ZATTACHMENT.Z_PK [where z_pk is the column from zattachment containing
matching data]
=ZVIBERMESSAGE.ZATTACHMENT [where zattachment is the column from
zvibermessage with matching data]
Adding the JOIN statements and the ZNAME to the working query looks like this:
SELECT
ZVIBERMESSAGE.ZTEXT
AS "Message Text",
ZATTACHMENT.ZNAME AS “Attachment Filename",
datetime(ZVIBERMESSAGE.ZDATE+978307200,'unixepoch','localtime')AS
"Message Date",
ZVIBERMESSAGE.ZSTATE
AS "Message Direction/State"
FROM
ZVIBERMESSAGE
LEFT JOIN ZATTACHMENT on ZATTACHMENT.Z_PK=ZVIBERMESSAGE.ZATTACHMENT
*New lines added to the query are bolded.