Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:42:55+00:00 2026-06-03T09:42:55+00:00

In the query below, I am trying to use the first table in a

  • 0

In the query below, I am trying to use the first table in a left outer join. However I am getting an error.

SELECT
       products.id,
       products_cstm.oem_c,
       products.mfr_part_num,
       products.description,
       products.cost,
       products.assigned_user_id,
       customfields_oo.ans
FROM products
          LEFT OUTER JOIN (SELECT  COUNT( q.id )  AS ans
                                  , pq.product_id
                           FROM   products_quotes pq 
                                     LEFT JOIN quotes q
                                           ON pq.quote_id = q.id
                           WHERE  q.deleted = 0
                           AND    pq.deleted = 0
                           AND    q.stage <> 4
                           AND  (pq.qty_shipped < pq.product_qty)
                           AND  pq.product_id = products.id
                           GROUP BY pq.product_id
                      ) AS customfields_oo
                ON customfields_oo.product_id = products.id
          LEFT JOIN products_cstm
                ON products.id = products_cstm.id_c
WHERE  products.deleted = 0
ORDER  BY ans DESC

When I run the query it gives me the following error:

Error Code : 1054
Unknown column 'products.id' in 'where clause'

It is not allowing first “products” table in left outer join query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:42:57+00:00Added an answer on June 3, 2026 at 9:42 am

    The issue is that customfields_oo is a derived table not a correlated subquery. Thus, you cannot reference the outer table from within the definition of the derived table. In this case, you cannot refer to the outer products table from within the customfields_oo definition. Instead, you must do that filter in the On clause outside the dervied table definition.

    Select products.id,
           products_cstm.oem_c,
           products.mfr_part_num,
           products.description,
           products.cost,
           products.assigned_user_id,
           customfields_oo.ans
    FROM products
        Left Join   (
                    Select pq1.product_id
                        , Count( q1.id ) As ans
                    From products_quotes As pq1 
                        Left Join quotes As q1
                            On pq1.quote_id = q1.id
                    Where q1.deleted = 0
                        And pq1.deleted = 0
                        And q1.stage <> 4
                        And pq1.qty_shipped < pq1.product_qty
                    Group By pq1.product_id
                    ) As customfields_oo
            On customfields_oo.product_id = products.id
        Left Join products_cstm
            On products.id = products_cstm.id_c
    Where products.deleted = 0
    Order By customfields_oo.ans Desc
    

    Now, you have stated in comments that this is too slow because, say products where deleted <> 0 might be evaluated in the derived table. If that is the case, then simply expand the derived table to include the filters on the outer products table.

    Select products.id,
           products_cstm.oem_c,
           products.mfr_part_num,
           products.description,
           products.cost,
           products.assigned_user_id,
           customfields_oo.ans
    FROM products
        Left Join   (
                    Select pq1.product_id
                        , Count( q1.id ) As ans
                    From products_quotes As pq1 
                        Join products As p1
                            On p1.products.id = pq1.product_id
                        Left Join quotes As q1
                            On pq1.quote_id = q1.id
                    Where q1.deleted = 0
                        And pq1.deleted = 0
                        And q1.stage <> 4
                        And pq1.qty_shipped < pq1.product_qty
                        And p1.deleted = 0
                    Group By pq1.product_id
                    ) As customfields_oo
            On customfields_oo.product_id = products.id
        Left Join products_cstm
            On products.id = products_cstm.id_c
    Where products.deleted = 0
    Order By customfields_oo.ans Desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the query below. Using a LEFT OUTER join takes 9 seconds to
Why does the MySQL query below give error 1066 (Not unique table/alias: 'customer') ?
I am trying to use the below query in a stored procedure to get
The query below is trying to select a child node of a given Node.
I have below query I am trying to show message 'No SubSource for this
I am trying to get the below linq query to return -1 if there
I'm trying to mesh the below mysql query results into a single json object,
Description I'm trying to JOIN a table using the result of a stored function.
When I run the decorate_keyword() function below, I'm getting two errors that I'm trying
I am trying to change the SQL query below to HQL in my grails-groovy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.