Wrox Programmer Forums
|
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
 
Old March 1st, 2005, 08:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default SQL Query

Hi All,
I have a list of records with "CORP_ID" and "INITIAL" columns
I am trying to delete records with the following condition;
Group the records based on "CORP_ID" and "INITIAL" columns and delete the records where the initial "JM" is not part of this group.
In this example, 3rd row (512 - GR) should be deleted.

CORP_ID INITIAL
346 JM
346 LB
512 GR
742 JM
742 LB
742 LH

Thanks for your help,

:)


MCinar

Love all the creatures because of the creator.
__________________
MCinar

Love all the creatures because of the creator.
 
Old March 1st, 2005, 09:43 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

May be there is an easier way but here is my query

DELETE
FROM MyTable AS T1
WHERE T1.CORP_ID NOT IN (SELECT T3.Corp_ID FROM (SELECT T2.CORP_ID,T2.INITIAL
FROM MyTable T2
GROUP BY CORP_ID, INITIAL
HAVING INITIAL = 'JM') As T3);
 
Old March 1st, 2005, 10:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Chirag,
I tried and it worked very well.

Thanks for your help,



MCinar

Love all the creatures because of the creator.





Similar Threads
Thread Thread Starter Forum Replies Last Post
sql query i need seearam MySQL 7 November 30th, 2008 03:14 AM
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
SQL Query!! dpkbahuguna Beginning VB 6 5 October 12th, 2007 12:39 AM
Help with SQL query sattaluri Access 2 August 11th, 2006 09:26 AM
SQL query PinkyCat Classic ASP Databases 3 March 11th, 2005 01:41 PM





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