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 8414631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:12:56+00:00 2026-06-10T01:12:56+00:00

I need to delete values in a temp table based on both values in

  • 0

I need to delete values in a temp table based on both values in another. In other words, I do not want any item_desc left in B for an id that has a style_cd listed in A.

#tempA
style_cd char(3),
id_cd varchar(15)

Some sample values are like:

A, 123456
A, 654321
B, 321456
A, 654123
C, 424242

.

#tempB
item_desc varchar(50),
item_num char(4),
style_cd char(3),
id_cd varchar(15)

Sample values for this table:

item 1,  7, A, 123456
item 2, 14, B, 123456 
item 2, 14, A, 123456
item 3, 23, A, 123456
....snip....
item 2, 14, B, 654321
item 2, 14, A, 654321
item 6, 44, A, 654321

For example – for id 123456 I want to remove both entries for item 2 from B. Each item can have several styles associated with it. An id will usually only have one style associated with it but could conceivably have several.

I must be running into a block because this doesn’t seem that complicated. I have been working on this for two days and can’t get anything but all rows deleted. I have been trying something along the lines of:

DELETE #tempB
WHERE style_cd IN 
    (SELECT style_cd
     FROM #tempB b JOIN tempA a
     ON b.id_cd = a.id_cd
     AND b.style_cd = a.style_cd)

Of course this deletes all the rows and I can’t for the life of me figure out how to just get rid of only rows associated with the style_cd values listed for an id in Table A. I hope this makes sense and someone can put me out of my misery!!!!

I am using Sybase ASE 15.0.2

ADD…
I used @john’s suggestion as a starting point. When I test the select it picks out the rows I need for it to.

    SELECT a.style_cd
    FROM #tempB b
      JOIN #tempA a
      ON a.id_cd = b.id_cd
      AND a.style_cd = b.style_cd 

When I add in any Delete clause it wipes out everything

DELETE FROM #tempB
WHERE style_cd IN 
(SELECT style_cd
 FROM #tempB b JOIN tempA a
 ON b.id_cd = a.id_cd
 AND b.style_cd = a.style_cd)

Somehow I am not getting just the rows from the list in the select removed from tempB

  • 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-06-10T01:12:57+00:00Added an answer on June 10, 2026 at 1:12 am

    It’s just a simple confusion between DELETE #tempDB and DELETE *FROM* #tempDB

    Try your same query modified like so:

    DELETE FROM #tempB
    WHERE style_cd IN 
        (SELECT style_cd
         FROM #tempB b JOIN tempA a
         ON b.id_cd = a.id_cd
         AND b.style_cd = a.style_cd)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to delete from a table the entries where it has multiple values
I need to delete rows in a table, such as DELETE FROM TABLE_X WHERE
I need to delete a few fields from the table in the database. I
I need to delete some rows from csv file based on a column value.
I need to get stored procedure (not standart, only custom) to delete unused rows
I need to delete the first 29 values of an array. I searched and
i need to export 3 full sql table values in to a single excel
I need to write an Insert, Update Trigger on table A which will delete
I need help to know how to update values and how to delete a
I need to create Trigger for delete action which backsup all fields old value

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.