sql - Pick One Row per Unique ID from duplicate records -
in ms.access 2010, have similar query table 1 below displaying duplicate records. problem though have unique id's, 1 of field has different data other row since have combined 2 seperate tables in query. want display 1 row per id , eliminate other rows. doesn't matter row pick. see below:
id - name - favcolor 1242 - john - blue 1242 - john - red 1378 - mary - green
i want pick of the row same id. doesn't matter row pick long displaying 1 row per id matters.
id - name - favcolor 1242 - john - red 1378 - mary - green
use sql current query subquery , group by
id
, name
. can retrieve minimum favcolor
since want 1 , don't care which.
select sub.id, sub.name, min(sub.favcolor) ( select id, [name], favcolor table1 union select id, [name], favcolor table2 ) sub group sub.id, sub.name;
note name
reserved word. bracket name or prefix table name or alias avoid confusing db engine.
Comments
Post a Comment