The sum of all SQL Server matter that exist,
and the space in which all SQL Server events
occur or could occur.
Welcome to SQL Server Universe.com Sign in | Join | Help
in
Home SS SLUG Forums Articles Photos Downloads

Query request

Last post 05-07-2008, 11:27 by zahran. 1 replies.
Sort Posts: Previous
  • Query request

     05-07-2008, 10:44

    • Joined on 04-03-2007
    • Posts 12
    • Points 0
    • Top 10 Contributor

    DECLARE @TABLE TABLE
    (
        EmpID CHAR(3)
        ,Category CHAR(1)
    )

    INSERT INTO @TABLE VALUES('101','A')
    INSERT INTO @TABLE VALUES('102','B')
    INSERT INTO @TABLE VALUES('103','C')
    INSERT INTO @TABLE VALUES('104','A')
    INSERT INTO @TABLE VALUES('105','B')
    INSERT INTO @TABLE VALUES('106','C')
    INSERT INTO @TABLE VALUES('107','D')
    INSERT INTO @TABLE VALUES('108','A')
    INSERT INTO @TABLE VALUES('109','A')
    INSERT INTO @TABLE VALUES('110','D')

    I need to remove record from each duplicated values in [Category] field.
    Ex : One record from each A,B,C and D. Any Idea?
     

  • Re: Query request

     05-07-2008, 11:27

    • Joined on 04-03-2007
    • Posts 12
    • Points 0
    • Top 10 Contributor

    I found following query. Problem solved. 

    DELETE FROM @TABLE
    WHERE EmpID IN(SELECT MIN(EmpID) FROM @TABLE GROUP BY Category)

View as RSS news feed in XML

(Best viewed with a resolution of more than 1024 * 768)

Powered by Community Server, by Telligent Systems