In the following SQL, I have 2 tables (TRACTOR_TABLE and SOFTWARE_TABLE) that I am doing a LEFT JOIN on. If I remove the "GLOBAL_TABLE" from the end of the query, it works fine. However, I need to join the entire results of this query to another table, so that is why I need the lable at the end of the query. When I leave "GLOBAL_TABLE" in the query, I get an error that just says the syntax is correct. This confuses me though, because this query works:
SELECT
TRIP_MST_NO
FROM
(
SELECT
TRIP_MST_NO
FROM
TRIP_MASTER
) TESTING
That works, but it is the same principal as the query below which doesn't work when I leave the "GLOBAL_TABLE" label in. Can anybody please tell me why???
SELECT
TRIP_MST_NO,
TRACKING_POS_LOCATION
FROM
(
(
SELECT
TRIP_MST_NO,
TRIP_MST_TRACTOR,
TRIP_MST_STATUS,
TRIP_MST_ORIG_CITY,
TRIP_MST_ORIG_STATE
FROM
TRIP_MASTER AS ZZ
WHERE
TRIP_MST_STATUS IN ('B','D','A') AND
TRIP_MST_TRIP_LEG = (
SELECT
MAX(TRIP_MST_TRIP_LEG)
FROM
TRIP_MASTER
WHERE
TRIP_MST_NO = ZZ.TRIP_MST_NO
)
) TRACTOR_TABLE
LEFT JOIN
(
SELECT
QUAL_POS_UNIT AS TRACTOR_MAPPER,
MAX(QUAL_POS_ID) AS TRACKING_POS_ID,
QUAL_POS_LOCATION AS TRACKING_POS_LOCATION,
QUAL_POS_DATE_TIME AS TRACKING_POS_DATE_TIME
FROM
QUAL_POSITION
GROUP BY
QUAL_POS_UNIT, QUAL_POS_LOCATION, QUAL_POS_DATE_TIME
) SOFTWARE_TABLE
ON TRACTOR_TABLE.TRIP_MST_TRACTOR = SOFTWARE_TABLE.TRACTOR_MAPPER
) GLOBAL_TABLE
Thanks in advance!!!!!!!!!!!!
Mike