SQL 1064 Error, Syntax going unseen

时间:2017-12-02 00:31:37

标签: mysql sql django

SELECT
    i.*,
    ii.file_location
    FROM group_shop_item i, group_shop_itemimage ii, group_shop_brand b 
    WHERE 
    i.brand_id = b.id
    AND 
    b.brand_status_id = 1
    AND 
    i.is_deleted = 0
    AND 
    i.is_displayed = 1
    AND
    i.id = ii.item_id
    AND 
    ii.is_main = 1
    AND 
    i.deal_participate = 1 
    AND  
    i.brand_label_id IS NOT NULL
 ORDER BY i.datetime_modified DESC;

This SQL query keeps throwing me a 1064. It seems to be on the last line which I've tried with and without the i table variable. I can't for the life of me catch the error, anyone can lend me another pair of eyes?

I'm throwing this as a RAW query into the in built Django function and building this query with string concatenation. This copy paste is directly from a print I've done from the command line. It's outputting neatly but isn't reading when I run the view on my browser.

1 个答案:

答案 0 :(得分:3)

超过25年前,采用了ANSI标准连接语法。 您需要停止在from子句中的表名之间使用coma。

SELECT
      i.*
    , ii.file_location
FROM group_shop_item i
INNER JOIN group_shop_itemimage ii ON i.id = ii.item_id
INNER JOIN group_shop_brand b ON i.brand_id = b.id
WHERE i.is_deleted = 0
AND i.is_displayed = 1
AND ii.is_main = 1
AND i.deal_participate = 1
AND i.brand_label_id IS NOT NULL
AND b.brand_status_id = 1
;

关于1064错误,please read this没有确切的错误消息以及完全/完整的查询,我们无法提供更多信息。

另外需要注意的是“选择*”也不是好习惯。