#1066 - 不唯一的表/别名:

时间:2013-10-25 12:33:55

标签: mysql sql

你能帮我解决一下吗?我有这个SQL查询:

SELECT l.url 
FROM (b INNER JOIN links ON b.parent_id = l.id) 
INNER JOIN b ON l.id = b.link 
WHERE l.url LIKE 'http://domain%' LIMIT 0, 30

不知何故,它说

#1066 - Not unique table/alias: b

2 个答案:

答案 0 :(得分:9)

您好像是从同一张桌子中选择了两次。每个事件都需要自己的别名:

SELECT
    l.url
FROM
    b as b1 /* <-- */
    INNER JOIN links as l
      ON b1.parent_id = l.id
    INNER JOIN b as b2 /* <-- */
      ON l.id = b2.link
WHERE l.url LIKE 'http://domain%' LIMIT 0, 30

请注意,我还为l表添加了缺少的别名links

答案 1 :(得分:0)

SELECT l.url from b inner join links as l on l.id = l.parent_id
inner join b as b1 on b1.link = l.id
where l.url like 'http:domain%' limit 0,30

在此查询中,我们将两个表连接到第一个b和第二个链接,并自行连接b作为b1别名确定