Support » Fixing WordPress » WordPress database error: [Not unique table/alias

  • Resolved LFABIO

    (@lfabio)


    Hello,

    I have gotten this error on a website I am working on.

    WordPress database error: [Not unique table/alias: ‘jfr_comments’]
    SELECT SQL_CALC_FOUND_ROWS znfr_posts.*, AVG( jfr_commentmeta.meta_value ) as average_rating FROM jfr_posts INNER JOIN jfr_postmeta ON ( znfr_posts.ID = jfr_postmeta.post_id )LEFT JOIN jfr_comments ON(jfr_posts.ID = jfr_comments.comment_post_ID) LEFT JOIN jfr_commentmeta ON(jfr_comments.comment_ID = jfr_commentmeta.comment_id) LEFT OUTER JOIN jfr_comments ON(jfr_posts.ID = jfr_comments.comment_post_ID) LEFT JOIN jfr_commentmeta ON(jfr_comments.comment_ID = jfr_commentmeta.comment_id) WHERE 1=1 AND ( ( jfr_postmeta.meta_key = ‘_visibility’ AND CAST(jfr_postmeta.meta_value AS CHAR) IN (‘visible’,’catalog’) ) ) AND jfr_posts.post_type = ‘product’ AND ((jfr_posts.post_status = ‘publish’)) AND jfr_commentmeta.meta_key = ‘rating’ AND ( jfr_commentmeta.meta_key = ‘rating’ OR jfr_commentmeta.meta_key IS null ) GROUP BY jfr_posts.ID ORDER BY average_rating DESC, jfr_posts.post_date DESC LIMIT 0, 24

    I really don’t know where to start to solve it.
    Thank you for your help and attention!

    LFABIO

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello, I did study SQL on Codeschool before I tried some plugins: WP-Optimize, Advanced Database Cleaner and even was thinking in start learning about Queries to solve this issue, as nobody showed here on WordPress to give any help. :\ Sad.
    Was thinking in uploading WP-DBManager and did uploaded Query-monitor 2.11.4 Before doing anything else I updated WooCommerce and all the error run out. Funny is that I deactivated all plugins and understood the trouble was with WooCommerce, but I did not see any article explaining about or showing WooCommerce as a possible plugin to be fixed in cases like that, see those words: ‘visible’, ‘catalog’, ‘product’, ‘publish’.
    Thanks to me, who is learning in the hard way as many.
    P.S.: I see many people posts are not getting any help.
    WordPress users must watch and help the beginners!!!
    lfabio

    Long time no replies! Just found this today because I have the same or similar error on a project. The cause is implied in the error message, the same table is being joined twice. Or the same alias (for the table name) is used twice. It’s hard to read these long sql statements but if you suspect a certain table is duplicated, search the statement for it and find out where it’s being used. When you find a “double join” or duplicate join, figure out a solution. Can’t tell you exactly how to solve it, still researching myself, try this stack overflow: http://stackoverflow.com/questions/4267929/whats-the-best-way-to-join-on-the-same-table-twice

    In my own project the reason for the double-join is because we have a system where we’re creating the query in a loop, and it creates an array of joins. In some cases, the joins are for the same table. We might be able to fix it with using a different alias… still researching.

    Hope this helps, 9-months later hopefully you solved it already.

    Moderator t-p

    (@t-p)

    9-months later hopefully you solved it already.

    @goldhat, This thread is not only 9 months old, but @lfabio has already marked this thread “resolved”!!

    If you are looking for topics that could benefit from your help, try looking in https://wordpress.org/support/view/no-replies

    This thread is closed now

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress database error: [Not unique table/alias’ is closed to new replies.