Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6755513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:24:37+00:00 2026-05-26T13:24:37+00:00

I feel like I am a decent SQL programmer; however, I came upon a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:24:38+00:00Added an answer on May 26, 2026 at 1:24 pm

    This should illustrate my take on your requirements:

    create table #tmp_media (VIN char(1), MediaID int)
    create table #tbInventoryMedia (VIN char(1), MediaID int)
    
    insert #tmp_media
    select Vin = 'X', MediaId=20223
    union select 'Y',  54235
    union select 'Z',  20223
    
    insert #tbInventoryMedia
    select vin = 'X',  MediaId = 20223
    union select 'X', 32131
    union select 'Y', 54235
    union select 'Z', 20223
    union select 'A', 20223
    union select 'A', 12345
    
    select * from #tbInventoryMedia
    
    delete im
    from
        #tbInventoryMedia im
        join (select distinct VIN from #tmp_media) as uq on uq.VIN = im.VIN
        left join #tmp_media m on m.MediaID = im.MediaID and m.VIN = im.VIN
    where m.MediaID is null
    
    select * from #tbInventoryMedia
    
    
    drop table #tmp_media
    drop table #tbInventoryMedia
    

    I’ve added some data for the “A” VIN, which I beleive should be left alone. In this example only X, 32131 gets removed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this should have a simple answer, but I can't find it.
I feel like this should be an easy question but I can't seem to
I feel like I'm missing something pretty basic, but I can't seem to figure
I am pretty new to Haskell but I feel like I have a decent
I feel like I'm re-inventing the wheel here, but I need to find a
When working with R, I feel like a have decent repertoire of tools and
Sorry If something like this has already been asked, but I can't find exactly
I feel like this is a very noob question.. but I just can't get
Feel like this should be something easy that I'm missing. I have a table
I feel like this must be simple to do but can't get it done

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.