0

i am trying to execute this query but it is not working correctly.

SELECT *
        FROM posts P
        LEFT JOIN post_status PS ON PS.post_id = P.post_id
        LEFT JOIN users U ON U.user_id = P.post_author
        WHERE
        P.post_cat = '5'
        AND P.is_hide = '0'
        ORDER BY post_views DESC
        LIMIT 8

i want to filter those posts having "is_hide" field is 0. but it also shows the result that have value is_hide = 1. Where is problem..

4

1 回答 1

0

Your query appears to be missing a where clause.

SELECT *
    FROM posts P
    LEFT JOIN post_status PS ON PS.post_id = P.post_id
    LEFT JOIN users U ON U.user_id = P.post_author
    WHERE P.post_cat = 5
    AND P.is_hide = 0
    ORDER BY post_views DESC
    LIMIT 8

Also, on top of this, if these are integer columns you should compare directly and not single quote.

于 2013-04-26T03:08:21.193 回答