Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear,

I am Viswanathan.M.
My Question is, I need to get a last 50 percent of datas from the table.
ie.,

I have 100 rows in a table.Now i need to get last 50 datas from that table. For this tell the SQL server 2005 Query.
Posted
Comments
Mohankumar.Engain 9-Apr-11 5:54am    
i Already that doubt thanks... Mr.vishwa

by mohan

If the amount of rows can change, you could try something like this:
SQL
SELECT TOP((SELECT COUNT(*) FROM MyTable) / 2) 
       * 
FROM MyTable
ORDER BY ColumnThatDefinesTheOrderForPercentage DESC


Or simply use PERCENT and order the data in descending order, like:
SQL
SELECT TOP(50) PERCENT
       *
FROM MyTable
ORDER BY ColumnThatDefinesTheOrderForPercentage DESC
 
Share this answer
 
v2
Comments
Mahendra.p25 9-Apr-11 5:25am    
Great
hi,

You can use

select Top(50) * from Table Orderby(PrimayKeyColumn) desc 

//another way

select Top (50)* from Table where Id Not in (Select  Top(50) Id from Table )
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900