Select the first row in a join of two tables in one statement

后端 未结 8 1842
名媛妹妹
名媛妹妹 2020-12-29 12:59

I need to select only the first row from a query that joins tables A and B. On table B exist multiple records with same name. There are not identifiers in any of the two tab

8条回答
  •  醉话见心
    2020-12-29 13:26

    You can use row number to get one row for each name, try something like below

    Select name,data1,data2 from 
    (Select A.NAME,B.DATA1,B.DATA2,row_number() over(partitioj by a.name order by a.name) rn
    From A 
    Inner Join B on A.NAME = B.NAME) where rn=1
    

提交回复
热议问题