I wouldn't bother noting the trap IDs. If you were going to do that for records or such you would archive them out somehow. This basically removes [orphaned] data from TrapVarBinds table where there is no related trap id in the Traps table.
you don't have to do anything but run the query. the subquery in () gets the list and feeds to main query.
Also note that the query will only remove any trap details from the TrapsVarBinds if the trap ID does not exist in the Traps table.
If you are receiving a large number of traps, you will continue to see these messages. If you have trap retention still set to the default 7 days, you are receiving almost 900,000 traps a day. On a Summary page, you can add the Traps Summary resource and it will tell you how many traps you have received by trap type, IP address, hostname, or machine type. This will allow you to narrow down what devices are sending the majority of traps and what traps they are. From there, you can determine if you still need these traps or disable them.