Query Table - trying to figure out how to pull in data from another table?

Query Table - trying to figure out how to pull in data from another table?

I'm trying to write a query that will pull a column from "Purchase Order Items" into my query, but I'm not sure how to link it.  It has a column called "Product ID" that is the same value as the existing "Product ID" already in the query - so I'm trying to grab costs from the "Purchase Order Items" table but everything I've tried keeps saying no table found - so apparently a lookup table is not needed, and instead, I must link the table in the query somehow?

How can I do this?

Here is the existing query:

SELECT
 "Invoices"."Invoice Number" "Invoice Number",
 "Invoices"."Invoice Date" "Invoice Date",
 "Sales Persons"."Name" "Sales Person",
 "Invoices"."Ship Method" "Ship Method",
 "Invoice Items".*,
 if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) as 'Item Cost',
 (if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity") as 'Total Line Cost',
 "Invoice Items"."Total (BCY)" -(if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity") as 'Invoice Line Profit',
 "Items"."SKU" "SKU",
 "Invoice Items"."Cost" "Invoice Items Cost",
 "Sales Order Items"."Cost" "SO Items Cost",
 "Items"."Purchase Price" "Items Price",
 "Total Monthly Profit"."Total Month Profit" "Total Month Profit",
 if("Total Monthly Profit"."Total Month Profit"  < 8000, 0, if("Total Monthly Profit"."Total Month Profit"  < 10000, .16, if("Total Monthly Profit"."Total Month Profit"  < 15000, .18, if("Total Monthly Profit"."Total Month Profit"  < 20000, .2, if("Total Monthly Profit"."Total Month Profit"  < 25000, .21, if("Total Monthly Profit"."Total Month Profit"  < 35000, .22, if("Total Monthly Profit"."Total Month Profit"  < 45000, .23, if("Total Monthly Profit"."Total Month Profit"  < 55000, .235, if("Total Monthly Profit"."Total Month Profit"  < 65000, .24, if("Total Monthly Profit"."Total Month Profit"  < 75000, .245, if("Total Monthly Profit"."Total Month Profit"  >= 75000, .25, 0))))))))))) "Commission Rate",
 ("Invoice Items"."Total (BCY)" -(if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")) * (if("Total Monthly Profit"."Total Month Profit"  < 8000, 0, if("Total Monthly Profit"."Total Month Profit"  < 10000, .16, if("Total Monthly Profit"."Total Month Profit"  < 15000, .18, if("Total Monthly Profit"."Total Month Profit"  < 20000, .2, if("Total Monthly Profit"."Total Month Profit"  < 25000, .21, if("Total Monthly Profit"."Total Month Profit"  < 35000, .22, if("Total Monthly Profit"."Total Month Profit"  < 45000, .23, if("Total Monthly Profit"."Total Month Profit"  < 55000, .235, if("Total Monthly Profit"."Total Month Profit"  < 65000, .24, if("Total Monthly Profit"."Total Month Profit"  < 75000, .245, if("Total Monthly Profit"."Total Month Profit"  >= 75000, .25, 0)))))))))))) "Commission Amount",
 If((if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")  = 0, 100, (if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")) 'Mindys Total Line Cost',
 ("Invoice Items"."Total (BCY)" -(if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")) / ((if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")) * 100 as 'Profit 1',
 (If((if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")  = 0, 1, (if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity"))) * 100 as 'For calculation',
 (If((if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")  = 0, 100, (("Invoice Items"."Total (BCY)" -(if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")) / ((if_Null(if_Null("Invoice Items"."Cost", ifNull("Sales Order Items"."Cost", "Items"."Purchase Price")), 0) * "Invoice Items"."Quantity")) * 100))) as 'Final Profit % per Invoice'
FROM  "Invoice Items"
LEFT JOIN "Invoices" ON "Invoices"."Invoice ID"  = "Invoice Items"."Invoice ID" 
LEFT JOIN "Sales Persons" ON "Sales Persons"."Sales Person ID"  = "Invoices"."Sales Person ID" 
LEFT JOIN "Items" ON "Items"."Item ID"  = "Invoice Items"."Product ID" 
LEFT JOIN "Sales Order Items" ON "Sales Order Items"."Item ID"  = "Invoice Items"."SO ItemID" 
LEFT JOIN "Total Monthly Profit" ON "Total Monthly Profit"."Salesperson"  = "Sales Persons"."Name"
 AND "Total Monthly Profit"."Month/Year"  = date_format("Invoices"."Invoice Date", '%m/%Y')  

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation
                                              • Sticky Posts

                                              • Announcing Zoho Analytics 6.0 Beta!

                                                We are delighted to open up the next major version, Zoho Analytics 6.0 Beta! The new version comes packed with a wide range of functionalities for all persona, namely business users, data analysts, data engineers, and data scientists. Zoho Analytics team
                                              • What's New in Zoho Analytics - August 2024

                                                Hello Users! We are back with the latest updates and enhancements made to Zoho Analytics. Keep reading to learn more about them. Connect to the data hosted in the cloud without allow-listing the IP addresses Utilize Zoho Databridge to connect to the data
                                              • We are coming to your city! Zoho Analytics Community Meetup

                                                Hello, business leaders and data enthusiasts! We are delighted to announce that registrations are now open for the ZUG meetups, and we can't wait for you to be a part of them. Our in-house analytics experts are geared up to lead discussions on constructing
                                              • Zoho Analytics: 2021 Look Back

                                                As we start a new year in 2022, here's some of our top moments from 2021. Zoho Analytics in 2021
                                              • [Customer Talk] PREMO Group's Analyst Interview at Zoho Day 2022

                                                Premo Group, a 50 year old Spanish Manufacturing Company, has been our long-standing customer with #ZohoAnalytics. They've been using our platform for their end-to-end, unified business analytics solution.  Hear more from Claudio Cabeza, Director at PREMO


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now