-1

I've created two tables, simplecomments and commentors, and joined them with INNER JOIN on commentors.id = simplecomments.commentorid.

Commentors is the personal info of a commenter with following columns: number(id), name, email..

Simplecomments is details of each and every commenter, containing comment, reg_date, commentorid, deliverytype, rating... I've joined them successfully, however I'm finding it hard to delete from the joined table.

I want to make it like this:

if there's last row of a commentor called.. let say A, then delete both his comment details and A himself from the table.

Else if A has commented plenty of times, (with different comments), delete his comment details, but let his personal info remain since he, A, has other comments there..

How should I proceed?

misterManager
  • 1,174
  • 4
  • 12
  • 33
Gullit
  • 139
  • 8
  • 1
    didn't you post this earlier? https://stackoverflow.com/questions/47238602/deleting-a-row-with-inner-join – Funk Forty Niner Nov 11 '17 at 15:31
  • Possible duplicate of [Deleting a row with inner join](https://stackoverflow.com/questions/47238602/deleting-a-row-with-inner-join) – Nic3500 Nov 11 '17 at 16:14

1 Answers1

1

this is a sort of unusual but totally doable request:

check out this sql fiddle: http://sqlfiddle.com/#!9/3dc5e6/1

essentially, a conditional delete should patch you up, assuming you run it after each delete.... which I would personally do so manually but you can also use a trigger. Essentially the trigger would run the conditional delete after each delete of a SimpleComment.

misterManager
  • 1,174
  • 4
  • 12
  • 33