I feel like I am a decent SQL programmer; however, I came upon a situation that I can’t seem to find an elegant solution to solve. There are two tables in my database, a tmp_media table and a tbInventoryMedia table. I want to delete all of the media from tbInventoryMedia that does not exist in the tmp_media table. However, there is a distinct column called VIN – some VINs can have the same media as others.
Example:
tmp_media
Vin MediaId
X 20223
Y 54235
Z 20223
tbInventoryMedia
vin MediaId
X 20223
X 32131
Y 54235
Z 20223
In the above example, the vin of X would be deleted where mediaId is 34131.
Lastly, tmp_media does not contain an exhaustive list of all VINs, only those that have been recently processed. So there will be other media in tbInventoryMedia that needs to be left alone. Only VINs that are located in the tmp_media table are to have any data removed.
If additional clarification is needed, let me know – I imagine that this is very confusing.
This should illustrate my take on your requirements:
I’ve added some data for the “A” VIN, which I beleive should be left alone. In this example only
X, 32131gets removed