Seeder question
I am trying to query a table, returning all the columns, and order by the fourth column (but show this first), however I am getting this error. What have I done wrong?
declare @somedata table
(
col1 int,
col2 int,
col3 int,
col4 int
)
insert into @somedata select 1,1,1,1
insert into @somedata select 2,2,2,2
insert into @somedata select 3,3,3,3
insert into @somedata select 4,4,4,4
insert into @somedata select 5,5,5,5
insert into @somedata select 6,6,6,6
select col4,* from @somedata
order by col4
gives me the error
Msg 209, Level 16, State 1, Line 16
Ambiguous column name 'col4'.
Edit > As well as workarounds, I would like to know why the error occurs too!