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


Help in the Delete Statement


Help in the Delete Statement

Author
Message
montse 22199
montse 22199
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: 63
Hello all,
I need to delete a record that is duplicate between 2 tables.

The query looks like this:

Delete from request_form_table_testing as t1
where EXISTS
(select tEmail from request_form_temp_emails as t2
where t1.email = t2.tEmail)

but is giving me an error:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'as'.

I dont really know where is my syntax error.

Could you guys help me?

Thanks a lot
Sean Lange
Sean Lange
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: General Forum Members
Points: 65228 Visits: 17979
montse 22199 (3/20/2013)
Hello all,
I need to delete a record that is duplicate between 2 tables.

The query looks like this:

Delete from request_form_table_testing as t1
where EXISTS
(select tEmail from request_form_temp_emails as t2
where t1.email = t2.tEmail)

but is giving me an error:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'as'.

I dont really know where is my syntax error.

Could you guys help me?

Thanks a lot


You can't alias the table in your delete statement. You can do the same thing a number of different ways. Here are a couple of them.


Delete request_form_table_testing
where tEmail in
(
select tEmail
from request_form_temp_emails as t2
join request_form_table_testing t1 on t1.email = t2.tEmail
)

delete request_form_table_testing
from request_form_table_testing as t1
where EXISTS
(select tEmail from request_form_temp_emails as t2
where t1.email = t2.tEmail)



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
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