I have created a temp table and inserted the values as given below.
create table #temp( val int ); insert into #temp values(333); insert into #temp values(222); insert into #temp values(111);
On querying the below select statement I got 333 as the answer.
Select * from #temp a Where 1 =( Select COUNT(VAL) from #temp b where a.val <= b.val );
Can you please help me understand how SQL server came to this solution.