我在编写查询时遇到问题。让我说我有一个完整的汽车品牌和模型表,但我想摆脱与模型列表无关的所有行,我写了这个......
DELETE FROM `cars` WHERE
`make` != 'Ford' OR
`make` != 'Toyota' OR
`make` != 'Cadillac'
然而,它正在删除所有行。我如何写这篇文章以便保留福特,丰田和Cadiillac,但删除庞蒂亚克,达特森和雷诺?
感谢您对此的帮助!
答案 0 :(得分:11)
易于阅读:
DELETE FROM `cars` WHERE `make` NOT IN ('Ford', 'Toyota', 'Cadillac')
答案 1 :(得分:4)
DELETE FROM cars
WHERE make <> 'Ford'
AND make <> 'Toyota'
AND make <> 'Cadillac'
您的查询正在删除所有行,因为: