unique column

  • I have a access database table 'CustomerDetails' which has 3 columns CName,CADD,CScore

    Now I want to query this table so that I get only records with all the 3 columns where CName is unique.

    In the table 'CustomerDetails' Cname is not a primary key

    Thanks

  • Select Distinct (CNAME) From CustomerDetails




    My Blog: http://dineshasanka.spaces.live.com/

  • But I also want to display CADD,CScore along with CNAME

  • WHen you add in CADD and CSCORE you will get duplicate names if you have multiple different entries in either of those fields. If you want all the CADD and CSCORE fields but want to group them in you display under a single CNAME then you are talkign about your presentation layer of your application and that has many different potentials based on the applications programming language as to how to go about. If you only want a particular CADD and CSCORE then what criteria decides that and are there more columns involved to check for the criteria?

  • Can u put some sample data here




    My Blog: http://dineshasanka.spaces.live.com/

  • select CName,CADD,CScore

    from CustomerDetails

    where CName in ( Select CName From CustomerDetails group by CName having count(*) = 1)

  • If you do not care about the values in CADD and CScore, you can use this query:

    Select CName, max(CADD),max(CScore) from Customerdetails

    group by CName;

    Note : You can use any group function - min or max (or avg for Cscore).

    R_achar

     

     

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply