MYSQL删除记录(MYSQL deleting a record)

嗨,大家做了一些更多的修改,如何做到以下几点:

删除属于“A Wilks”的甲壳虫

person (driver-id, name, address) car (license, model, year) accident (report-number, date, location) owns (driver-id, license) participated (driver-id, car, report-number, damage-amount)

这是我想出的:

DELETE FROM car WHERE model = 'beetle'

但我知道这是错误的,因为它会删除所有的甲壳虫车而不仅仅是A Wilks所拥有的那辆车。

hi guys doing some more revision, how do the following:

Delete the Beetle belonging to “A Wilks”

person (driver-id, name, address) car (license, model, year) accident (report-number, date, location) owns (driver-id, license) participated (driver-id, car, report-number, damage-amount)

here is what i have come up with:

DELETE FROM car WHERE model = 'beetle'

however i know this is wrong because it will delete all the beetle cars and not just the one owned by A Wilks.

最满意答案

DELETE FROM car WHERE model = 'beetle' AND license = ( SELECT o.license from owns o INNER JOIN person p ON o.driver-id = p.driver-id WHERE p.name = 'A Wilks' ) DELETE FROM car WHERE model = 'beetle' AND license = ( SELECT o.license from owns o INNER JOIN person p ON o.driver-id = p.driver-id WHERE p.name = 'A Wilks' )MYSQL删除记录(MYSQL deleting a record)

嗨,大家做了一些更多的修改,如何做到以下几点:

删除属于“A Wilks”的甲壳虫

person (driver-id, name, address) car (license, model, year) accident (report-number, date, location) owns (driver-id, license) participated (driver-id, car, report-number, damage-amount)

这是我想出的:

DELETE FROM car WHERE model = 'beetle'

但我知道这是错误的,因为它会删除所有的甲壳虫车而不仅仅是A Wilks所拥有的那辆车。

hi guys doing some more revision, how do the following:

Delete the Beetle belonging to “A Wilks”

person (driver-id, name, address) car (license, model, year) accident (report-number, date, location) owns (driver-id, license) participated (driver-id, car, report-number, damage-amount)

here is what i have come up with:

DELETE FROM car WHERE model = 'beetle'

however i know this is wrong because it will delete all the beetle cars and not just the one owned by A Wilks.

最满意答案

DELETE FROM car WHERE model = 'beetle' AND license = ( SELECT o.license from owns o INNER JOIN person p ON o.driver-id = p.driver-id WHERE p.name = 'A Wilks' ) DELETE FROM car WHERE model = 'beetle' AND license = ( SELECT o.license from owns o INNER JOIN person p ON o.driver-id = p.driver-id WHERE p.name = 'A Wilks' )