Lani Vriezema
asked on
SQL - UNION QUERY REVIEW COMMAND
Hello,
I am trying to join two tables and I am not sure if I wrote the command right.
SELECT "PRT_CURRENT__TIME"."Perio d_End_Date ", "PRT_CURRENT__TIME"."Units ", "PRT_CURRENT__TIME"."Pay_I D", "PRT_CURRENT__TIME"."Job", "JCM_MASTER__JOB"."Descrip tion", "PRT_CURRENT__TIME"."Amoun t", "PRT_CURRENT__TIME"."Emplo yer_Taxes" , "PRT_CURRENT__TIME"."Fring es", "PRT_CURRENT__TIME"."Cash_ Fringes", "PRM_MASTER__EMPLOYEE"."Em ployee_Nam e", "JCM_MASTER__JOB"."Cost_Ac count_Pref ix"
FROM ("\\TEST\Timberline Data\TEST\"."PRT_CURRENT__ TIME" "PRT_CURRENT__TIME" INNER JOIN "\\TEST\Timberline Data\TEST\"."JCM_MASTER__J OB" "JCM_MASTER__JOB" ON "PRT_CURRENT__TIME"."Job"= "JCM_MASTE R__JOB"."J ob") INNER JOIN "\\TEST\Timberline Data\TEST\"."PRM_MASTER__E MPLOYEE" "PRM_MASTER__EMPLOYEE" ON "PRT_CURRENT__TIME"."Emplo yee"="PRM_ MASTER__EM PLOYEE"."E mployee"
WHERE "PRT_CURRENT__TIME"."Perio d_End_Date ">={d '2019-12-12'} AND "JCM_MASTER__JOB"."Cost_Ac count_Pref ix"='20'
ORDER BY "JCM_MASTER__JOB"."Cost_Ac count_Pref ix", "PRT_CURRENT__TIME"."Job", "PRM_MASTER__EMPLOYEE"."Em ployee_Nam e"
UNION
SELECT "PRT_EXECCURENT__TIME"."Pe riod_End_D ate", "PRT_EXECCURENT__TIME"."Un its", "PRT_EXECCURENT__TIME"."Pa y_ID", "PRT_EXECCURENT__TIME"."Jo b", "JCM_EXECMASTER__JOB"."Des cription", "PRT_EXECCURENT__TIME"."Am ount", "PRT_EXECCURENT__TIME"."Em ployer_Tax es", "PRT_EXECCURENT__TIME"."Fr inges", "PRT_EXECCURENT__TIME"."Ca sh_Fringes ", "PRM_EXECMASTER__EMPLOYEE" ."Employee _Name", "JCM_EXECMASTER__JOB"."Cos t_Account_ Prefix"
FROM ("\\TEST\Timberline Data\TEST\"."PRT_EXECCUREN T__TIME" "PRT_EXECCURENT__TIME" INNER JOIN "\\TEST\Timberline Data\TEST\"."JCM_EXECMASTE R__JOB" "JCM_EXECMASTER__JOB" ON "PRT_EXECCURENT__TIME"."Jo b"="JCM_EX ECMASTER__ JOB"."Job" ) INNER JOIN "\\TEST\Timberline Data\TEST\"."PRM_EXECMASTE R__EMPLOYE E" "PRM_EXECMASTER__EMPLOYEE" ON "PRT_EXECCURENT__TIME"."Em ployee"="P RM_EXECMAS TER__EMPLO YEE"."Empl oyee"
WHERE "PRT_EXECCURENT__TIME"."Pe riod_End_D ate">={d '2019-12-12'} AND "JCM_EXECMASTER__JOB"."Cos t_Account_ Prefix"='2 0'
ORDER BY "JCM_EXECMASTER__JOB"."Cos t_Account_ Prefix", "PRT_EXECCURENT__TIME"."Jo b", "PRM_EXECMASTER__EMPLOYEE" ."Employee _Name"
I am trying to join two tables and I am not sure if I wrote the command right.
SELECT "PRT_CURRENT__TIME"."Perio
FROM ("\\TEST\Timberline Data\TEST\"."PRT_CURRENT__
WHERE "PRT_CURRENT__TIME"."Perio
ORDER BY "JCM_MASTER__JOB"."Cost_Ac
UNION
SELECT "PRT_EXECCURENT__TIME"."Pe
FROM ("\\TEST\Timberline Data\TEST\"."PRT_EXECCUREN
WHERE "PRT_EXECCURENT__TIME"."Pe
ORDER BY "JCM_EXECMASTER__JOB"."Cos
ASKER
Failed to retrieve data
ASKER
Should I join the tables and not specific columns from each table?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Kent,
Thank you for your help!
Best Regards,
Lani
Thank you for your help!
Best Regards,
Lani
UNION and UNION ALL are similar operations. If you want all the rows from both tables, use UNION ALL. Otherwise the duplicates will be filtered out.
Your sort columns are from the different tables. The UNION/UNION ALL operators require that the columns in both queries match in number and data type. Sorting on rows from each query suggests that the column lists may not match.
What happens when you run it?