How to delete after selection

Hi Experts

I need to make a deletion of a row that was selected within an inner select.

The idea is :
Select (select min(col) from tableA where tableA.ID = tableB.ID
WHERE tableA.ID = tableB.ID

) [colName]
From tableB

An alternate solution would too be highly appreciated

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
any chance of using real table and field names?
plus, sample data & expected result?
Jim HornMicrosoft SQL Server Data DudeCommented:
Give us a data mockup of what you're trying to pull off here, as looking at your question it's not clear.
PortletPaulEE Topic AdvisorCommented:
Please consider the following carefully, it may show that what you have asked for may result in unwanted data loss

I'm only using one table, but watch what happens to [id] = 1

    ([ID] int, [Value] decimal(6,2));
INSERT INTO Table1     ([ID], [Value])
    (1, 1.1),
    (2, 2.2),
    (2, 2.3),
    (2, 2.4),
    (3, 3.3),
    (3, 3.4),
    (3, 3.5),
    (3, 3.6)

Open in new window

;with CTE as (
            ,(select min(value)from table1 where table1.ID = B.ID) as [mincol]
        From table1 B
delete from table1
from table1
inner join CTE ON and table1.value = CTE.mincol

Open in new window

select * from table1

| ID | Value |
|  2 |   2.3 |
|  2 |   2.4 |
|  3 |   3.4 |
|  3 |   3.5 |
|  3 |   3.6 |

Open in new window

ID 1 has been deleted (because the value is = to min(value)
BUT also
there was only one row with ID=1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
COL exists in TableB? And is related to TableA.Col?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.