Search code examples
mysqlsqlpymysql

query sql to use with python


What's wrong with this query?

SELECT ps_stock_available.quantity 
FROM ps_stock_available 
INNER JOIN ps_product_attribute ON ps_product_attribute.id_product ON ps_stock_available.id_product 
WHERE ps_product_attribute.reference =100102

Solution

  • I think you intend:

    SELECT sa.quantity
    FROM ps_stock_available sa INNER JOIN
         ps_product_attribute pa 
         ON sa.id_product = pa.id_product
    WHERE pa.reference = 100102;
    

    Notes:

    • Use table aliases. They make the query easier to write and to read.
    • The ON clause contains a boolean expression.
    • A single JOIN has a single ON clause.