This is a pretty complex query so i am having difficulties here. If you help me i appreciate it.
select AvgLevel,TotalCount,tblPokedex.PokemonId,Name,Type1,Type2,Hp,tblPokedex.Attack,tblPokedex.Defense,tblPokedex.SpAttack,tblPokedex.SpDefense,tblPokedex.Speed,(Hp+tblPokedex.Attack+tblPokedex.Defense+tblPokedex.SpAttack+tblPokedex.SpDefense+tblPokedex.Speed) as TotalStats
from tblPokemonStats,tblAvailablePokemons,tblPokedex
left join tblUsersPokemons on tblPokedex.PokemonId=tblUsersPokemons.PokemonId
where tblPokemonStats.PokemonId=tblPokedex.PokemonId
group by tblPokedex.PokemonId,tblPokedex.Name,tblPokedex.Type1,tblPokedex.Type2,tblPokedex.Hp,tblPokedex.Attack,tblPokedex.Defense,tblPokedex.SpAttack,tblPokedex.SpDefense,tblPokedex.Speed,tblPokemonStats.AvgLevel,tblPokemonStats.TotalCount
order by PokemonId asc
Alright so what i want to do is for example select between top 100 and 150
How can i do that ?
Here’s one way – tack on a
row_numbercolumn and filter on that:row_numberdoes what it sounds like – it numbers your rows.Here’s another possibility – say you want rows X through Y. You can select the
TOP Yrows according to your order. Then use that a subquery and select theTOP Y-Xaccording to the opposite order.Assuming X = 100 and Y = 150:
As far as performance, I’m not sure which would be better. My gut says that the
ORDER BYapproach is better for pages near the ‘front’ so to speak, butrow_number()would be better for later pages (high X and Y). That’s just a guess though – run some tests and see what works for you.