[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need help for SQL query

Posted on 2014-08-06
2
Medium Priority
?
214 Views
Last Modified: 2014-08-06
I have the following table

EmployeeCode          City
AA1                               XXX
AA1                               NN
BB1                               XXX
BB1                                NN
CC1                                 XXX
DD1                                NN

in the above table - I need to delete employee has more than  one record and delete  only city='NN'
0
Comment
Question by:Varshini S
2 Comments
 
LVL 15

Accepted Solution

by:
Vikas Garg earned 2000 total points
ID: 40243640
Hi,

try this one

:with cte as
(
select employeecode,city,row_number () over (partition by employeecode order by city) sn from Table
)

Delete from CTE where SN > 1 and city = 'NN' 

Open in new window

0
 

Author Comment

by:Varshini S
ID: 40243885
Vikas Garg,

I am sorry. I need to SN=0 not >1 . Am I correct ?
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question