DELETE rows from a specific table

I need to delete some rows from a table.  I need confirmation of this delete statement.

delete *
from MattersQNVTRST q
where matters in (select matters from matters m where m.Matters = q.Matters and m.AreaOfLaw = 'catrst')

Open in new window


I want to make sure that only the rows in table MattersQnvtrst will be deleted and not the rows in table Matters.
huerita37Asked:
Who is Participating?
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.

Russ SuterSenior Software DeveloperCommented:
Yep. The FROM clause is the key. It will target only that table. The fact that you're selecting data from the matters table in a subquery doesn't affect the outer FROM clause. However, the WHERE clause should also refer to the outer table.

The naming is just a little confusing. It appears you have a column named "matters" inside a table named "matters". You also have a column named "matters" inside the table "MattersQNVTRST". It's not a good idea to name columns inside tables the same as the table names themselves.

For absolute clarity I'd rewrite it like this:
delete *
from MattersQNVTRST q
where q.matters in (select m.matters from matters m where m.Matters = q.Matters and m.AreaOfLaw = 'catrst')

Open in new window

It's saying the same thing but it disambiguates some of your names.

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
SThayaTechnical MAnagerCommented:
try the below query

delete  
from MattersQNVTRST q
where matters in (select matters from matters m where   m.AreaOfLaw = 'catrst')

and

there is a syntax error in your query .." * " will not support in SQL server.
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 2008

From novice to tech pro — start learning today.