I have two tables:
Table groupMessage is used for record group user Messages
Table groupMessageNum is used for record whose number of messages is more than 300.
-------------------
| groupMessage |
|-----------------|
| id |
| hostId |
| roomId |
===================
---------------------
| groupMessageNum |
|-------------------|
| id |
| hostId |
| roomId |
=====================
I am trying to delete the records in groupMessage that are in groupMessageNum and also delete the records in groupMessageNum.
If the number of the records in groupMessage to be deleted is more than 300, I will delete the records after 300th record.
my sql is :
delete group, groupNum from groupMessage group, groupMessageNum
groupNum where group.hostId = groupNum.hostId and group.roomId =
groupNum.roomId;
This will delete all the record in groupMessage.
So, how can I only delete the records after 300th?
Example:
There are 100 users and 60 users have more than 300 messages. All the user messages are in the groupMessage table. 60 user`s ids are in the groupMessageNum for their messages are more than 300.
Now i am trying to delete the use`s message which is after 300th message. So I firstly find the userid in the groupMessageNum table and then delete those messages in the groupMessage table.
You can try something like this:
or another way you may try this: