Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to group data which not the same ?

How to group data which not the same ?

Scheduled Pinned Locked Moved Database
helptutorialcsharpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Golden Jing
    wrote on last edited by
    #1

    Dear All, First i would like to sorry if my expliant not clear. My issue is that I want group data in field company name which not equal each other. It caused by inputting different users. Example: Company_Name ComxxxA Co. ComxxxA Co. ComxxxA Co.,Ltd. ComxxxA Co.,Ltd. ComxxxA Co., ComxxxA Co., ComxxxA ComxxxA Comx ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co ComxxxxxxxB Co., ComxxxxxxxB Co., ..... (there r alot company name which difference) So up to example above, what i want is the name is shortest ComxxxA Comx ComxxxxxxxB Co thanks for your help...

    VB.Net

    N L 2 Replies Last reply
    0
    • G Golden Jing

      Dear All, First i would like to sorry if my expliant not clear. My issue is that I want group data in field company name which not equal each other. It caused by inputting different users. Example: Company_Name ComxxxA Co. ComxxxA Co. ComxxxA Co.,Ltd. ComxxxA Co.,Ltd. ComxxxA Co., ComxxxA Co., ComxxxA ComxxxA Comx ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co ComxxxxxxxB Co., ComxxxxxxxB Co., ..... (there r alot company name which difference) So up to example above, what i want is the name is shortest ComxxxA Comx ComxxxxxxxB Co thanks for your help...

      VB.Net

      N Offline
      N Offline
      Niladri_Biswas
      wrote on last edited by
      #2

      Try this

      declare @t table(Company_Name varchar(50))
      insert into @t
      select 'ComxxxA Co.' union all select 'ComxxxA Co.' union all
      select 'ComxxxA Co.,Ltd.' union all select 'ComxxxA Co.,Ltd.' union all
      select' ComxxxA Co.,' union all select 'ComxxxA Co.,' union all
      select 'ComxxxA ' union all select 'ComxxxA ' union all
      select 'Comx' union all select 'ComxxxxxxxB Co.,Ldt' union all
      select 'ComxxxxxxxB Co.,Ldt' union all select 'ComxxxxxxxB Co.,Ldt' union all
      select 'ComxxxxxxxB Co.,Ldt' union all select 'ComxxxxxxxB Co' union all
      select 'ComxxxxxxxB Co.,' union all select 'ComxxxxxxxB Co.,'

      Query:

      select Company_Name
      from @t
      where replace(Company_Name, ' ','') not like '%[.,]%'
      group by Company_Name

      Output:

      Company_Name
      Comx
      ComxxxA
      ComxxxxxxxB Co

      :)

      Niladri Biswas

      G 1 Reply Last reply
      0
      • N Niladri_Biswas

        Try this

        declare @t table(Company_Name varchar(50))
        insert into @t
        select 'ComxxxA Co.' union all select 'ComxxxA Co.' union all
        select 'ComxxxA Co.,Ltd.' union all select 'ComxxxA Co.,Ltd.' union all
        select' ComxxxA Co.,' union all select 'ComxxxA Co.,' union all
        select 'ComxxxA ' union all select 'ComxxxA ' union all
        select 'Comx' union all select 'ComxxxxxxxB Co.,Ldt' union all
        select 'ComxxxxxxxB Co.,Ldt' union all select 'ComxxxxxxxB Co.,Ldt' union all
        select 'ComxxxxxxxB Co.,Ldt' union all select 'ComxxxxxxxB Co' union all
        select 'ComxxxxxxxB Co.,' union all select 'ComxxxxxxxB Co.,'

        Query:

        select Company_Name
        from @t
        where replace(Company_Name, ' ','') not like '%[.,]%'
        group by Company_Name

        Output:

        Company_Name
        Comx
        ComxxxA
        ComxxxxxxxB Co

        :)

        Niladri Biswas

        G Offline
        G Offline
        Golden Jing
        wrote on last edited by
        #3

        Thanks, Yes it like example. But it is not enough yet. Because in this field has more companies like that up to differenc user enter difference. So have any solution for protect it ?

        VB.Net

        N 1 Reply Last reply
        0
        • G Golden Jing

          Thanks, Yes it like example. But it is not enough yet. Because in this field has more companies like that up to differenc user enter difference. So have any solution for protect it ?

          VB.Net

          N Offline
          N Offline
          Niladri_Biswas
          wrote on last edited by
          #4

          [Message Deleted]

          G 1 Reply Last reply
          0
          • N Niladri_Biswas

            [Message Deleted]

            G Offline
            G Offline
            Golden Jing
            wrote on last edited by
            #5

            it is not complete what i want. but i would like to thank to you so much.

            VB.Net

            1 Reply Last reply
            0
            • G Golden Jing

              Dear All, First i would like to sorry if my expliant not clear. My issue is that I want group data in field company name which not equal each other. It caused by inputting different users. Example: Company_Name ComxxxA Co. ComxxxA Co. ComxxxA Co.,Ltd. ComxxxA Co.,Ltd. ComxxxA Co., ComxxxA Co., ComxxxA ComxxxA Comx ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co.,Ldt ComxxxxxxxB Co ComxxxxxxxB Co., ComxxxxxxxB Co., ..... (there r alot company name which difference) So up to example above, what i want is the name is shortest ComxxxA Comx ComxxxxxxxB Co thanks for your help...

              VB.Net

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, you can use SELECT DISTINCT[^] and ORDERBY to get an ordered list of all different company names present. you can't find the "shortest" names as in your example, it would only give "Comx", not what you said it would. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups