Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 5th, 2005, 01:16 PM
Authorized User
 
Join Date: Oct 2004
Location: Hyderabad, Andhra Pradesh, India.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to delete repeated records in a query

Hi,

My question is :

Table1:
Eid Ename
1 a
1 a
1 a
2 b
2 b

How to remove the repeated rows after deletion .

Ramkumar

A.D.Ramkumar
__________________
Ramkumar A D
Reply With Quote
  #2 (permalink)  
Old March 6th, 2005, 01:45 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   Is you question that you want to remove duplicate rows?


Reply With Quote
  #3 (permalink)  
Old March 7th, 2005, 01:05 AM
Authorized User
 
Join Date: Feb 2005
Location: Pune, Maharashtra, India.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Executed following statement in sequence:

Select distinct * into #tmpTable from Table1
Truncate Table Table1
Insert Into Table1 Select * from #tmpTable
Drop Table #tmpTable
Go

Cheers,
Pooja Falor
Reply With Quote
  #4 (permalink)  
Old March 7th, 2005, 11:23 AM
Friend of Wrox
 
Join Date: Jan 2004
Location: , , USA.
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if you wanted to remove duplicate rows

SELECT Eid, Ename
FROM myTable
Group By Eid,Ename
Having Count(*) >1

Reply With Quote
  #5 (permalink)  
Old March 10th, 2005, 12:09 PM
Authorized User
 
Join Date: Oct 2004
Location: Hyderabad, Andhra Pradesh, India.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Need a Single DELETE query to this

Ramkumar

A.D.Ramkumar
Reply With Quote
  #6 (permalink)  
Old March 10th, 2005, 04:10 PM
Friend of Wrox
 
Join Date: Jan 2004
Location: , , USA.
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DELETE
FROM MyTable
WHERE EID IN (SELECT EID FROM MyTable Group By EID,Ename Having Count(EID) > 1);


Reply With Quote
  #7 (permalink)  
Old March 12th, 2005, 11:09 AM
Authorized User
 
Join Date: Oct 2004
Location: Hyderabad, Andhra Pradesh, India.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sacchi,

Sorry, query didn't work perfectly.

I need an output after deleting repeated data.

Ramkumar

A.D.Ramkumar
Reply With Quote
  #8 (permalink)  
Old March 12th, 2005, 01:35 PM
Friend of Wrox
 
Join Date: Jan 2004
Location: , , USA.
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ramkumar, please provide us with a sample output

how you like your SQL to retrun your query output

Reply With Quote
  #9 (permalink)  
Old March 13th, 2005, 11:45 AM
Authorized User
 
Join Date: Oct 2004
Location: Hyderabad, Andhra Pradesh, India.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

output should be:

Eid Ename
1 a
2 b

Expecting your answer.

Ramkumar

A.D.Ramkumar
Reply With Quote
  #10 (permalink)  
Old March 13th, 2005, 02:44 PM
Friend of Wrox
 
Join Date: Jan 2004
Location: , , USA.
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you using SQL server or Access?

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
php/mysql delete button and delete query dungey PHP Databases 17 April 11th, 2009 12:24 PM
delete null records stealthdevil Access VBA 3 January 23rd, 2007 04:48 PM
delete records in database shoakat Classic ASP Databases 9 October 26th, 2004 08:31 PM
Delete X number of records slgknjn Access 1 August 22nd, 2004 08:24 AM
How to delete the dataset records jabby ADO.NET 18 August 1st, 2004 11:42 PM



All times are GMT -4. The time now is 05:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.