Mysql

Mysql查询并删除符合条件的子集

DELETE FROM purchase_suppliers_contract_materials_source
WHERE PSCMS_ID in(
	SELECT PSCMS_ID FROM(
		SELECT
			p1.PSCMS_ID
		FROM
			purchase_suppliers_contract_materials_source AS p1
		LEFT JOIN materials AS m ON p1.PSCMS_MATERIALS_ID = m.MATERIALS_ID
		LEFT JOIN (
			SELECT
				*
			FROM
				purchase_suppliers_contract_materials_source
		) AS p2 ON p1.PSCMS_PSC_ID = p2.PSCMS_PSC_ID
		AND p1.PSCMS_MATERIALS_ID = p2.PSCMS_MATERIALS_ID
		WHERE MATERIALS_ID is NULL) AS x
)

留言

您的电子邮箱地址不会被公开。 必填项已用*标注