sql server - SQL choose first of duplicate results -
hello have query returns computer names corresponding ip adress follows:
select distinct top (100) percent dbo.inv_aex_ac_tcpip.[ip address], dbo.inv_aex_ac_tcpip.[host name] dbo.inv_aex_ac_identification inner join dbo.inv_aex_ac_tcpip on dbo.inv_aex_ac_identification._resourceguid = dbo.inv_aex_ac_tcpip._resourceguid
this returning results such as:
computer: ip: frank's computer 10.0.0.1 frank's computer 10.0.0.3 nick's computer 10.0.1.0
is possible return first "frank's computer" row, , exclude other one?
thanks!
yes, possible, how depends on dbms of choice. functionality looking group by
, puts similar results in same column, need know non-aggregated values, putting them in aggregate function max
, min
or avg
.
your results fine this:
select min(dbo.inv_aex_ac_tcpip.[ip address]) ip, dbo.inv_aex_ac_tcpip.[host name] name dbo.inv_aex_ac_identification inner join dbo.inv_aex_ac_tcpip on dbo.inv_aex_ac_identification._resourceguid = dbo.inv_aex_ac_tcpip._resourceguid group dbo.inv_aex_ac_tcpip.[host name]
however choice of ip rather arbitrary (min
alphabetic sort). in sql server , oracle can define user defined aggregate function better select show, in mysql use group_concat
fit needs.
Comments
Post a Comment