2016-11-03 3 views
0

Ich habe die Update-Abfrage:Mysql-Update mit subquery beitreten

UPDATE cash_billings_bills_articles 
    SET cash_billings_bills_articles.cashbillingbillarticle_cost = (SELECT articles_pricehistory.articlepricehistory_cost 
              FROM articles_pricehistory 
              LEFT JOIN cash_billings_bills 
               ON cash_billings_bills_articles.cashbillingbill_id = cash_billings_bills.cashbillingbill_id 
              WHERE articles_pricehistory.article_id = cash_billings_bills_articles.article_id AND 
               articles_pricehistory.articlepricehistory_date <= cash_billings_bills.cashbillingbill_date 
              ORDER BY articles_pricehistory.articlepricehistory_date DESC 
              LIMIT 1 
              ); 

Aber ich habe den Fehler: Error Code: 1054. Unknown column 'cash_billings_bills_articles.cashbillingbill_id' in 'on clauseError Code: 1054. Unknown column 'cash_billings_bills_articles.cashbillingbill_id' in 'on clause' 0.000 sec

UPDATE Tabellen Strukturen:

enter image description here

+0

Ihre Tabellenstrukturen –

+0

@KiranMuralee zeigen Bitte laden Sie die Seite das Update –

Antwort

0

Ihre Joinbedingung scheint falsch zu sein. In Ihrer Abfrage versuchen Sie Tabellen zu verbinden articles_pricehistory an d cash_billings_bills unter der Bedingung

cash_billings_bills_articles.cashbillingbill_id = cash_billings_bills.cashbillingbill_id 

wo cash_billings_bills.cashbillingbill_id Säule sollte mit einer gewissen Spalte articles_pricehistory Tabelle nicht cash_billings_bills_articles Tabelle verglichen werden.

sollte Ihre Abfrage mehr sein wie

UPDATE cash_billings_bills_articles 
SET 
    cash_billings_bills_articles.cashbillingbillarticle_cost = (SELECT 
      articles_pricehistory.articlepricehistory_cost 
     FROM 
      articles_pricehistory 
       LEFT JOIN 
      cash_billings_bills_articles ON cash_billings_bills_articles.article_id = articles_pricehistory.article_id 
       LEFT JOIN 
      cash_billings_bills ON cash_billings_bills_articles.cashbillingbill_id = cash_billings_bills.cashbillingbill_id 
     WHERE 
      articles_pricehistory.articlepricehistory_date <= cash_billings_bills.cashbillingbill_date 
     ORDER BY articles_pricehistory.articlepricehistory_date DESC 
     LIMIT 1) 
+0

anzuzeigen Arbeitete !, Danke“ –

+1

@JonathanEdgardo froh zu wissen :) –