5

I have read alot of other answers but cannot get this working!.

select * from invTypes
inner join invGroups on invtypes.groupID = invgroups.groupID
where invGroups.categoryID = 25;

I simply want to delete the record from invTypes if the category ID matches to 25

Would be very grateful of assistance

I have already tried:

delete from invTypes
inner join invGroups on invtypes.groupID = invgroups.groupID
where invGroups.categoryID = 25;

Gives error: near "inner": syntax error:

DELETE FROM invTypes
WHERE groupID in ( SELECT groupID FROM invGroups INNER JOIN invTypes ON (invGroups.groupID = invTypes.groupID) 
WHERE invGroups.categoryID = 25);

Gives: ambiguous column name: groupID: DELETE FROM invTypes WHERE groupID in ( SELECT groupID FROM invGroups INNER JOIN invTypes ON (invGroups.categoryID = invTypes.categoryID) WHERE invGroups.categoryID = 25);

dai007uk
  • 148
  • 4
  • 11

2 Answers2

8

you can use delete with a where clause

delete from invTypes
where groupId in ( select groupId from invGroups where CategoryID =25)
radar
  • 13,270
  • 2
  • 25
  • 33
-2
DELETE invTypes
FROM invTypes
INNER JOIN invGroups
ON invTypes.groupID = invGroups.groupID
WHERE invGroups.categoryID = 25;
Andy
  • 49,085
  • 60
  • 166
  • 233