hana
hana

Reputation: 121

Joining with a distinct column

How do I join a table with a distinct value in a SQL view? My code looks like below

Select a, b, c, d from TableA inner join TableB on TableA.account = TableB.account

I want TableB.account to have distinct values when I join the table.

The selected fields(a,b,c,d) do not have to be distinct values.

Upvotes: 0

Views: 1255

Answers (1)

gvee
gvee

Reputation: 17161

SELECT distinct_foo.thing
     , bar.other_things
FROM   (
        SELECT DISTINCT
               thing
        FROM   foo
       ) AS distinct_foo
 INNER
  JOIN bar
    ON bar.thing = distinct_foo.thing
;

Upvotes: 1

Related Questions