The
final step before adding the JOIN statements to the query is to add in a
statement for including the ZNAME since this is the column that contains the
username desired in the final output. This is accomplished just as in prior
examples where the column name is included after the SELECT statement.
Ex:
ZNAME AS “Username”
To
add the JOIN statement, you must include:
The
table you want to JOIN and the column from that table that matches a column in
the existing table.
In
the example:
JOIN
ZMEMBER (the table being added)
on
ZMEMBER.Z_PK [where z_pk is the column from zkikuser containing matching
data]
=ZVIBERMESSAGE.ZPHONENUMINDEX [where zuser is the
column from zkikmessage with matching data]
Adding the JOIN statements and the ZNAME to the working query looks like this:
SELECT
ZMEMBER.ZNAME AS "Username",
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
LEFT JOIN ZMEMBER on ZMEMBER.Z_PK=ZVIBERMESSAGE.ZPHONENUMINDEX
*New lines added to the query are bolded.