I have an error in purchasedetail table when I am trying to fetch this record. This is my select query:
SELECT itemstock.itemId
FROM itemstock
JOIN item ON item.itemId = purchasedetail.itemId
JOIN purchasemaster ON purchasemaster.purchaseMasterId = purchasedetail.purchaseMasterId
JOIN purchasedetail ON purchasedetail.itemId = item.itemId
JOIN party ON party.partyId = purchasemaster.partyId
WHERE
purchasemaster.partyId = ".$_REQUEST['partyId']."
AND itemstock.quantity > 0
GROUP BY itemName,itemCode
This is the error:
#1054 - Unknown column 'purchasedetail.itemId' in 'on clause'
When joining tables, the columns you join "on" have to belong to those tables. You are trying to join on columns from other tables that you haven't mentioned yet. Try this:
SELECT itemstock.itemId
FROM itemstock
JOIN item ON item.itemId = itemstock.itemId
JOIN purchasedetail ON purchasedetail.itemId = item.itemId
JOIN purchasemaster ON purchasemaster.purchaseMasterId = purchasedetail.purchaseMasterId
JOIN party ON party.partyId = purchasemaster.partyId
WHERE purchasemaster.partyId = 5 AND itemstock.quantity > 0 GROUP BY itemName,itemCode
Related
How do I fix my code so it runs correctly? It keeps telling me I have Error Code:
Error Code: 1054. Unknown column 'Number_Of_Ticketed_Events' in 'order clause').
Below is my code
SELECT Venue.VenueID, Venue.Capacity, VenueName,
COUNT(*) AS Number_Of_Ticketed_EventsĀ
FROM (
(Events INNER JOIN Non_Ticketed_Events)
INNER JOIN Venue ON Venue.VenueID = Events.VenueID
)
GROUP BY Events.VenueID
ORDER BY Number_Of_Ticketed_Events DESC;
Each JOIN needs telling which columns to use to make the join between the 2 tables
SELECT Venue.VenueID, Venue.Capacity, VenueName,
COUNT(*) AS Number_Of_Ticketed_Events
FROM Events e
INNER JOIN Non_Ticketed_Events nt ON Events.someColumn = nt.someColumn
INNER JOIN Venue ON Venue.VenueID = Events.VenueID
. . .
I have the following statement:
SELECT
p1.order_id,
p1.job_id,
j1.`status` AS p1_status
FROM
wildcard_orders AS p1,
wildcard_orders AS p2
LEFT JOIN wildcard_jobs AS j1 ON p1.job_id = j1.id
LEFT JOIN wildcard_jobs AS j2 ON p2.job_id = j2.id
WHERE
p1.order_id = p2.order_id
AND p1.job_id != p2.job_id
Basically, I am trying to get duplicate order_id that have a different job_id in the same table.
I've narrowed it down to including the same table in the FROM clause but I am sure I have done this before!
The exact error I get back is:
1054 - Unknown column 'p1.job_id' in 'on clause'
Can anyone help with why?
You can try this:
SELECT
p1.order_id,
p1.job_id,
j1.`status` AS p1_status
FROM
wildcard_orders AS p1
INNER JOIN wildcard_orders AS p2 ON p1.order_id = p2.order_id
LEFT JOIN wildcard_jobs AS j1 ON p1.job_id = j1.id
LEFT JOIN wildcard_jobs AS j2 ON p2.job_id = j2.id
WHERE p1.job_id != p2.job_id
NOTE: Do not use comma to join tables and explicit join syntax at same time.
I have the update query:
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
);
But i got the error: 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 Tables Structures:
Your join condition seems to be wrong .In your query you try to join tables articles_pricehistory and cash_billings_bills on condition
cash_billings_bills_articles.cashbillingbill_id = cash_billings_bills.cashbillingbill_id
where cash_billings_bills.cashbillingbill_id column should be compared with some column of articles_pricehistory table not cash_billings_bills_articles table.
Your query should be more like
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)
I'm very new in comlex SQL queries. So, I'm trying to debug SQL statement generated by Magento:
SELECT `e`.*,
`cat_index`.`position` AS
`cat_index_position`,
price_index.price AS
`indexed_price`,
`price_index`.`price`,
`price_index`.`final_price`,
IF(`price_index`.`tier_price`, Least(`price_index`.`min_price`,
`price_index`.`tier_price`),
`price_index`.`min_price`) AS
`minimal_price`,
`price_index`.`min_price`,
`price_index`.`max_price`,
`price_index`.`tier_price`,
GROUP_CONCAT(CONVERT(catalog_product_relation.child_id, CHAR(8))) AS
`children`,
`sfoi`.`price` AS
`confprice`
FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index`
ON cat_index.product_id = e.entity_id
AND cat_index.store_id = 1
AND cat_index.visibility IN( 2, 4 )
AND cat_index.category_id = '3'
INNER JOIN `catalog_product_index_price` AS `price_index`
ON price_index.entity_id = e.entity_id
AND price_index.website_id = '1'
AND price_index.customer_group_id = 0
INNER JOIN `catalog_product_index_eav` AS `attributeA`
ON attributeA.entity_id = e.entity_id
AND attributeA.attribute_id = '184'
AND attributeA.store_id = '1'
AND attributeA.value IN ( 50 )
INNER JOIN `catalog_product_index_eav` AS `attributeB`
ON attributeB.entity_id = e.entity_id
AND attributeB.attribute_id = '185'
AND attributeB.store_id = '1'
AND attributeB.value IN ( 95 )
LEFT JOIN `catalog_product_relation`
ON e.entity_id = catalog_product_relation.parent_id
LEFT JOIN `catalog_product_flat_1` AS `sfoi`
ON sfoi.entity_id = `children`
GROUP BY `e`.`entity_id`
ORDER BY `confprice` DESC
LIMIT 9
Everything work fine until:
LEFT JOIN `catalog_product_flat_1` AS `sfoi`
ON sfoi.entity_id = `children`
I get following error:
#1054 - Unknown column 'children' in 'on clause'
I've seen smilar posts, but I can't seem to figure it out by myself. Please, help me.
EDIT:
PHP code that generates this query:
$this->_collection->getSelect()->
joinLeft(
'catalog_product_relation',
'e.entity_id = catalog_product_relation.parent_id',
'GROUP_CONCAT(CONVERT(catalog_product_relation.child_id, CHAR(8))) as children'
);
$this->_collection->getSelect()->joinLeft('catalog_product_flat_1 AS sfoi',
'sfoi.entity_id = children',
'sfoi.price AS confprice'
)->order('confprice desc');
Actually, I'm trying to join two tables (catalog_product_relation and catalog_product_flat_1). But I can't get access to the "children" column after joining first table.
Add the corresponding column to children table in the ON condition.
ON sfoi.entity_id = catalog_product_relation.child_id
I am getting a SQL error that I don't understand. This is the error I get:
Database error: Invalid SQL:
SELECT distinct prodotti.nome, prodotti.id, prodotti.image_news,
imgprod.path, imgprod.alt
FROM `prodotti`, `categorie`, `prodcat`,
`gruppi` INNER JOIN imgprod ON prodotti.id = imgprod.idprod
LEFT OUTER JOIN radiation
ON prodotti.radiation_id = radiation.id_radiation
LEFT OUTER JOIN installation
ON prodotti.installation_id = installation.id_installation
WHERE 1=1 and prodotti.id = prodcat.idprod
and prodcat.idcat = categorie.id
and categorie.idgruppo = gruppi.id
and (gruppi.nome like 'ANT%' OR gruppi.nome like 'WIR%')
AND radiosystem LIKE '%VHF%'
GROUP BY prodotti.id ORDER BY prodotti.nome ASC
And this is another error I'm getting:
INNER JOIN MySQL Error: 1054 (Unknown column 'prodotti.id' in 'on clause')
This works on an old server, but on a new server with php 5.3.16 I am getting these errors. Can you please explain what the error means?
Your query rewritten using only explicit ANSI-style joins might look like
SELECT p.id, p.nome, p.image_news, i.path, i.alt
FROM prodotti p JOIN prodcat pc
ON p.id = pc.idprod JOIN categorie c
ON pc.idcat = c.id JOIN gruppi g
ON c.idgruppo = g.id JOIN imgprod i
ON p.id = i.idprod LEFT JOIN radiation r
ON p.radiation_id = r.id_radiation LEFT JOIN installation n
ON p.installation_id = n.id_installation
WHERE 1 = 1
AND (g.nome LIKE 'ANT%' OR g.nome LIKE 'WIR%')
AND radiosystem LIKE '%VHF%'
GROUP BY p.id, p.nome, p.image_news, i.path, i.alt
ORDER BY p.nome
It's impossible to tell more than that not seeing exact table schemas.