SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DELETE using INNER JOIN


DELETE using INNER JOIN

Author
Message
FootyRef
FootyRef
SSC-Enthusiastic
SSC-Enthusiastic (175 reputation)SSC-Enthusiastic (175 reputation)SSC-Enthusiastic (175 reputation)SSC-Enthusiastic (175 reputation)SSC-Enthusiastic (175 reputation)SSC-Enthusiastic (175 reputation)SSC-Enthusiastic (175 reputation)SSC-Enthusiastic (175 reputation)

Group: General Forum Members
Points: 175 Visits: 74
I was not the one who originally asked the question. I just searched and found this answer to a problem I was having here deleting records using a JOIN. I am using the SQLTerm tool within Cognos Data Manager and that was how the SQL was formed when the tool did it, so I just cut and pasted it into this thread to show the solution to my issue.
inception
inception
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 2
Hello,

I'm quite new to SQL. Is there any way someone could re-write the statement posted above, to generic terms? i.e., with Table 1, Table 2, Column 1, etc.

DELETE a
FROM "dbo"."DM_ConformedPerson" a
JOIN "dbo"."TST_Fix_DM_ConformedPerson" z
ON a."Person_SK" = z."Person_SK"
WHERE z."Person_SK" <> z."MaxSK"

thanks all!
Vikash Anil
Vikash Anil
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 14
Use following




DELETE ord
FROM Orders ord
INNER JOIN Customers c(nolock)
ON ord.CustomerID = c.CustomerID
WHERE c.FirstName = 'vikash'


regards,

blog.learnonlinewithme.com
das_bhasker
das_bhasker
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 11
Thanks Rajat, Your solutions saved my hours.

Thanks again Smile
sagscorp22
sagscorp22
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 3
I know. It's old post still thanks.
I was doing delete from too.
Your reply helped.
brahmaji_85 79292
brahmaji_85 79292
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 9
Thanks a lot.........:-)
turkey-500673
turkey-500673
SSC-Enthusiastic
SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)

Group: General Forum Members
Points: 102 Visits: 57
Thanks for this. I was going nuts with syntax error until I saw your script that used th alias instead of the table name. Simple but brilliant!
thanks again.:-)
kapilraut02
kapilraut02
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 2
SELECT * into #tempDocFragToDelete FROM
DocumentFragmentRelationShipHistory WHERE DocumentFragmentMasterId =391
AND DocumentFragmentVersionID=1.0


DELETE a from DocumentFragmentRelationShipHistory a join #tempDocFragToDelete b
on a.DocumentFragmentMasterId = b.DocumentFragmentMasterId
where a.DocumentFragmentVersionID > b.DocumentFragmentVersionID


This one is a real running example, try this.
forsqlserver
forsqlserver
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4474 Visits: 2060
Hi vikash,

In my case I want to delete those data which is not selecting in below join any Help..


DELETE ord FROM Orders ord INNER JOIN Customers c(nolock) ON ord.CustomerID = c.CustomerID WHERE c.FirstName = 'vikash'

Thanks
Kingston Dhasian
Kingston Dhasian
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5948 Visits: 5280
forsqlserver (7/23/2012)
Hi vikash,

In my case I want to delete those data which is not selecting in below join any Help..


DELETE ord FROM Orders ord INNER JOIN Customers c(nolock) ON ord.CustomerID = c.CustomerID WHERE c.FirstName = 'vikash'


Please create a separate thread for your problem
Also note that this is an old thread and the person you are referring to might not be online always to help you out

If you create a new thread with some sample data and DDL of the tables invloved, I am sure there are many here who can help out in no time
If you don't know how to do this, go through the link in my signature


Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search