我的mysql查询有问题.. 查询是:
DELETE address_book.*, address_book_tags.*, address_book_tags_contacts.* from address_book, address_book_tags, address_book_tags_contacts
LEFT JOIN address_book_tags_contacts on address_book.id = address_book_tags_contacts.contactId
LEFT JOIN address_book_tags on address_book_tags_contacts.tagId = address_book_tags.id
WHERE address_book.idVitalStatistic=1;
错误是:
RuntimeException',带有消息'Not unique table / alias:'address_book_tags_contacts'(1066)'
我该怎么办?
答案 0 :(得分:0)
你在FROM中有一个表address_book_tags_contacts和address_book_tags,就像LEFT JOIN一样。如果这是故意的(我不这么认为),你必须给他们一个独特的名字。但我想你应该从FROM子句中删除这些表名。
答案 1 :(得分:0)
address_book_tags_contacts 需要别名,就像这样;)
DELETE address_book.*, abt1.*, abtc1.*
FROM
address_book, address_book_tags abt1, address_book_tags_contacts abtc1
LEFT JOIN address_book_tags_contacts abtc2 ON ...
LEFT JOIN address_book_tags abt2 ON ...
@Steve这个查询实际上要删除什么。
答案 2 :(得分:0)
address_book_tags, address_book_tags_contacts
出现两次。
删除重复的:
DELETE address_book.*, address_book_tags.*, address_book_tags_contacts.*
from address_book
LEFT JOIN address_book_tags_contacts on address_book.id = address_book_tags_contacts.contactId
LEFT JOIN address_book_tags on address_book_tags_contacts.tagId = address_book_tags.id
WHERE address_book.idVitalStatistic=1;
答案 3 :(得分:0)
尝试:
DELETE address_book, address_book_tags, address_book_tags_contacts from address_book
LEFT JOIN address_book_tags_contacts on address_book.id = address_book_tags_contacts.contactId
LEFT JOIN address_book_tags on address_book_tags_contacts.tagId = address_book_tags.id
WHERE address_book.idVitalStatistic=1;