MySQL 查询以显示附加到我的媒体库的 Envira Gallery 标签及其相关 post ID

MySQL query to display the Envira Gallery Tags and their related post ID that are attached to my media library

我有一个查询构建,但我总是收到以下错误: [错误] 1066 - 不唯一 table/alias:'tt'

SELECT
    t.term_id,
    t. NAME,
    t.slug,
    pm.meta_value,
    tt.taxonomy,
    tr.object_id,
    tr.term_order
FROM
    wp_terms AS tt
INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN wp_postmeta AS pm ON pm.post_id = tr.object_id
WHERE
    tt.taxonomy = "envira-tag"
AND pm.meta_key = "_wp_attached_file"

我查看了您的查询,最近我做了一个类似的查询。错误指向使用 "tt" 次数过多。

此处您已经在使用 "tt" 用于不同的 table:

INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id

看起来别名 "tt" 实际上应该是 "t"。

FROM
    wp_terms AS t

使用别名时请确保您的请求与您引用的内容一致。