Skip to content
Advertisement

mysql gives a syntax error with many joins [closed]

it’s about an hour that I’m trying to understand why this query gives:

syntax error near ‘WHERE players.player_user=1 AND players.player_status=0 GROUP BY players.playe’ on line 108

I have mysql 5.6. Please ask in comments if you need more info to answer, I posted my entire query because this question is about a syntax error and not about how to make a query. This is the query:

SELECT 
    players.*, 
    users.user_username AS player_username, 
    users.user_image AS player_user_image, 
    r.ranking AS player_position, 
    prod_info.* 
FROM players 
LEFT JOIN users 
ON player_user=user_id 
LEFT JOIN 
(
    SELECT *, 
    (
        SELECT 1 + COUNT(*) 
        FROM players p2 
        WHERE p2.`player_step`=p.`player_step` 
            AND p2.player_score > p.player_score 
            AND p.player_status=0
    ) 
    AS ranking 
    FROM players p 
    ORDER BY `player_step`, player_score DESC
) 
AS r 
ON r.player_id=players.player_id 
LEFT JOIN 
(
    SELECT 
        products.*, 
        COUNT(order_id) AS prod_sold, 
        name.lang_it AS prod_name_it, 
        name.lang_en AS prod_name_en, 
        category.lang_it AS category_name_it, 
        category.lang_en AS category_name_en, 
        img.img_sm AS prod_image_sm, 
        img.img_md AS prod_image_md, 
        img.img_lg AS prod_image_lg, 
        IF(COUNT(wish.wish_id) > 0, 1, 0) AS prod_is_wish, 
        placed.tickets AS prod_tickets_placed, 
        placed.step_id AS prod_step, 
        IF(persons.num IS NULL, 0, persons.num) AS prod_players 
    FROM products 
    LEFT JOIN orders 
    ON (order_product=prod_id AND order_status>2) 
    LEFT JOIN categories AS cat 
    ON prod_category=cat_id 
    LEFT JOIN languages AS name 
    ON name.lang_id=prod_name 
    LEFT JOIN languages AS category 
    ON cat_name=category.lang_id 
    LEFT JOIN 
    (
        SELECT 
            IF(t.step_tickets IS NULL, d.step_tickets, t.step_tickets) AS tickets, 
            t.`step_product`, 
            t.`step_id` 
        FROM 
        (
            SELECT 
                `step_tickets`, 
                `step_product`, 
                `step_id` 
            FROM steps 
            LEFT JOIN players 
                ON (players.player_step=step_id AND players.player_user=1 AND players.player_status=0) 
            WHERE `step_status`=0
        ) 
        AS t, 
        (
            SELECT 
                `step_tickets`, 
                `step_product`, 
                `step_id` 
            FROM steps 
            WHERE `step_status`=0 AND step_product=1 AND `step_number`=1
        ) 
        AS d 
    )
    AS placed 
    ON placed.step_product=products.prod_id 
    LEFT JOIN 
    (
        SELECT 
            p.num, 
            players.player_user, 
            p.step_product 
        FROM 
        ( 
            SELECT 
                COUNT(players.player_id) AS num, 
                steps.step_id, 
                steps.step_product 
            FROM steps 
            LEFT JOIN players 
            ON players.player_step=steps.step_id 
            GROUP BY steps.step_id
        ) 
        AS p 
        LEFT JOIN players 
        ON players.player_step=p.step_id
    ) 
    AS persons 
    ON persons.player_user=1 AND persons.step_product=prod_id 
    LEFT JOIN images AS img 
    ON (prod_id=img.img_product AND img.img_order=0)
) 
AS prod_info
WHERE players.player_user=1 AND players.player_status=0 
GROUP BY players.player_id 
ORDER BY (people.tickets / products.prod_tickets * 100) DESC

Have anyone an idea? Thank you

Advertisement

Answer

AS prod_info doesn’t have an on clause.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement