sql - select TOP n Rows from table where n is in another table? -
how can achieve without using dynamic sqlquery?
i have query,
select top n mytable id = @id
to value of n,
select ncount myanothertable id = @id
can use row_index() this?
try this....but make sure select ncount
return single row.....if not select top row ncount
select top(select top 1 ncount myanothertable id = @id) * mytable id = @id
sqlfiddle: http://www.sqlfiddle.com/#!3/75c76/1
Comments
Post a Comment