Results 1 to 7 of 7

Thread: Select unique column in sql server

  1. #1
    Join Date
    Mar 2010
    Posts
    182

    Select unique column in sql server

    Hello,
    I am using sql server 2000 and I have a table with three columns name cone, ctwo and cthree. Now I would like to select unique column from it. For example if there are two columns of similar fields then I would like to fetch information these two columns but in a unique way. If you know how to do this then please let me know. Thank you for your help.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Select unique column in sql server

    Hello,
    You can try the following query, though I am not sure that this is the one that your need
    Code:
    select colnm, datatyp, chmaxlength 
    from infosch.columns
    where tabnm = 'myTable'

  3. #3
    Join Date
    Nov 2009
    Posts
    359

    Re: Select unique column in sql server

    Hello,
    See the below query this may help you
    Code:
    SELECT
    frnm, lsnm, etc.,
    MIN(date_column),
    MAX(date_column)
    FROM
    table
    GROUP BY
    frnm, lsnm, etc.,
    ORDER BY zip

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Select unique column in sql server

    Hello,
    Alternatively you can try the following sql query
    Code:
    select top 3 dv.[nm], dv.mnnum
    from (
    select [nm], max(number) as mnnum
    from #test
    group by [nm]
    ) dv
    order by dv.mnnum desc

  5. #5
    Join Date
    Nov 2009
    Posts
    583

    Re: Select unique column in sql server

    Hello,
    I think this is the query which you are looking for
    Code:
    SELECT epnum, strdt, jobno
    FROM tbnm as A
    WHERE strdt =
    (SELECT MAX(B.strdt)
    FROM tbnm as B
    WHERE A.epnum = B.epnum)

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: Select unique column in sql server

    Hello,
    You can use the following
    Code:
    SELECT x.*, x.cy + ',' + x.state AS CityState
    FROM zipcdtb x
    INNER JOIN (SELECT cy, state, MAX(zip) AS zip
                         FROM zipcdtb b
                         GROUP BY cy, state
                       ) b
                       ON b.cy = x.cy and b.state = x.state and b.zip = x.zip

  7. #7
    Join Date
    Nov 2009
    Posts
    356

    Re: Select unique column in sql server

    Hi,
    This is just a syntax but I think can help you

    Code:
    ALTER TABLE tble
       ALTER COLUMN mclm
           VARCHAR(50)
           NOT NULL
           DEFAULT 'some default value'

Similar Threads

  1. Select unique values using xsl
    By Elizabeth Allen in forum Software Development
    Replies: 6
    Last Post: 17-05-2010, 10:27 AM
  2. Select unique values without using distinct
    By Maya Angelou in forum Software Development
    Replies: 6
    Last Post: 17-05-2010, 10:26 AM
  3. Select unique records from a table
    By Conraad in forum Software Development
    Replies: 5
    Last Post: 13-05-2010, 12:01 AM
  4. Select unique columns from a record set
    By Madhuchhanda in forum Software Development
    Replies: 6
    Last Post: 12-05-2010, 11:31 PM
  5. SELECT UNIQUE and SELECT DISTINCT
    By TAARIQ in forum Software Development
    Replies: 3
    Last Post: 03-06-2009, 10:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,208,271.55423 seconds with 17 queries