sql server - Ambiguous column name SQL -


i following error when want execute sql query:
"msg 209, level 16, state 1, line 9 ambiguous column name 'i_id'."

this sql query want execute:

select distinct x.* items x left join items y on y.i_id = x.i_id , x.last_seen < y.last_seen x.last_seen > '4-4-2017 10:54:11'  , x.spot = 'spot773'  , (x.technology = 'bluetooth le' or x.technology = 'epc gen2')  , y.id null group i_id 

this how table looks like:

create table [dbo].[items] ( [id]         int           identity (1, 1) not null, [i_id]       varchar (100) not null, [last_seen]  datetime2 (0) not null, [location]   varchar (200) not null, [code_hex]   varchar (100) not null, [technology] varchar (100) not null, [url]        varchar (100) not null, [spot]       varchar (200) not null, primary key clustered ([id] asc)); 

i've tried couple of things i'm not sql expert:)
appreciated

edit:

i duplicate rows when remove group line can see: enter image description here

i'm adding answer in order show how you'd typically select lastest record per group without getting duplicates. you's use row_number this, marking every last record per i_id row number 1.

select * (   select      i.*,     row_number() on (partition i_id order last_seen desc) rn   items    last_seen > '2017-04-04 10:54:11'    , spot = 'spot773'    , technology in ('bluetooth le', 'epc gen2')  ) ranked rn = 1; 

(you'd use rank or dense_rank instead of row_number if wanted duplicates.)


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -