sql server - Join two tables and return only one row from second table -
sql server - Join two tables and return only one row from second table -
i have 2 tables. both tables contains id can used bring together them together. however, table 2 can have more 1 row same id
. table 1 have 1 row.
for instance, table 1
contains 60,000 rows. when left inner bring together table2
returns ~171 000 rows.
what i'm trying accomplish homecoming first row table 2 when bring together them not create duplicate records.
i'm not sure if right approach tried:
select i.*, a.name table 1 inner bring together (select min (a.id), a.name table 2 grouping a.id) on i.id = a.id
i next error:
incorrect syntax near 'i'.
any suggestions on how can prepare this? or result in different way?
something guarantee 1 row per id sec table.
;with singlerows ( select * , row_number() on (partition id order name) rownum table_2) select * table_1 t1 bring together singlerows t2 on t1.id = t2.id , t2.rownum = 1
sql-server sql-server-2012
Comments
Post a Comment