Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2005
    Posts
    266

    Unanswered: one column DISTINCT on 2 Tables

    hello I am trying to get a distinct on one column and 2 tables but it doesnt work

    Table1
    ID_Table1
    Name1
    Number1

    Table2
    ID_Table2
    ID_Table1
    Name2



    I want to get : ID_Table1, DISTINCT(Name1), Name2
    WHERE Name1 LIKE 'A%'

    how can I do it ?

    thank you

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    DISTINCT is not a function

    does your query join these tables?

    could you show your actual query please?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2005
    Posts
    266
    yes of course the 2 tables are JOIN by Table1.ID_Table1 AND Table2.ID_Table1

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    and you want one result row per value of Name1, correct?

    okay, here is one way --
    Code:
    select Table1.Name1
         , min(Table1.ID_Table1)
         , max(Table2.Name2)
      from Table1
    inner
      join Table2
        on Table2.ID_Table1 = Table1.ID_Table1 
     where Table1.Name1 like 'A%'
    group
        by Table1.Name1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Dec 2005
    Posts
    266
    it works fine !

    thanks again !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •