mysql join

Discussion in 'MySQL' started by promotingspace.net, Sep 3, 2008.

  1. #1
    Hi
    I have tables producs abd prod_subcat but i can't join the with this code:
    I echoed the query and it is:
    SELECT * FROM products pp,prod_subcat ps WHERE (`pp.productID` LIKE 
    '%40%' OR `productName` LIKE '%40%' OR `productDescription` LIKE '%40%' 
    OR `productColour` LIKE '%40%' OR `productID` LIKE '%%' OR `productName` 
    LIKE '%%' OR `productColour` LIKE '%%' ) AND ((ps.subcategoryID='8' AND 
    ps.productID=pp.productID ) OR (ps.subcategoryID='7' AND 
    ps.productID=pp.productID ))ORDER BY productID LIMIT 0,50
    PHP:
    current error:
    Unknown column 'products.productID' in 'where clause'
     
    promotingspace.net, Sep 3, 2008 IP
  2. cont911

    cont911 Peon

    Messages:
    50
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you sure you have productID field in products table?
    If yes, try to simplify the query, start with this for example:
    SELECT * FROM products pp, prod_subcat ps
    WHERE ps.productID=pp.productID
    LIMIT 0,50

    P.S too many OR make your query slower, as each OR means you run one more query
    P.P.S "LIKE '%%'" looks strange, try to remove OR-conditions without exact values
     
    cont911, Sep 3, 2008 IP
  3. maestria

    maestria Well-Known Member

    Messages:
    705
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    It would be good practise to keep the table name in front of the field, when using multiple tables.
     
    maestria, Sep 7, 2008 IP