DELETE B.*
FROM m_productprice B
INNER JOIN m_product C ON B.m_product_id = C.m_product_id
WHERE C.upc = '7094' AND B.m_pricelist_version_id = '1000020'
我得到以下错误PostgreSQL 8.2.11
ERROR: syntax error at or near "B"
LINE 1: DELETE B.* from m_productprice B INNER JOIN m_product C ON ...
我试着给予
DELETE B from m_productprice B INNER JOIN m_product C ON B....
ERROR: syntax error at or near "B"
我试着给予
ERROR: syntax error at or near "INNER"
LINE 1: DELETE from m_productprice B INNER JOIN m_product C ON B.m_...
我的查询有什么问题?
基本上这里提到的所有东西都在文档中提到了,但没有人具体说明是什么。这就是当前DELETE docs, Notes部分所说的:
PostgreSQL lets you reference columns of other tables in the WHERE condition by specifying the other tables in the USING clause. For example, to delete all films produced by a given producer, one can do:
DELETE FROM films USING producers
WHERE producer_id = producers.id AND producers.name = 'foo';
What is essentially happening here is a join between films and producers, with all successfully joined films rows being marked for deletion. This syntax is not standard. A more standard way to do it is:
DELETE FROM films
WHERE producer_id IN (SELECT id FROM producers WHERE name = 'foo');
In some cases the join style is easier to write or faster to execute than the sub-select style.