Reputation: 351
I am creating a new table in SQL Server. I would like to insert rows from another table, and I want to include Name, Team, Receptions, Yards, and Touchdowns. I would like to select the top six receivers with the most yards.
My query looks like this at the moment:
insert into ProBowl (Name, Team, Receptions, Yards, Touchdowns)
select top 6 from Widereceivers;
When I do this, it just returns the first six rows - but it does not sort by yardage. How can I do this?
Upvotes: 1
Views: 1582
Reputation: 5119
Order By in Sql.
From the documentation I linked above:
[ASC] Specifies an ascending order for the query results. ASC is the default order for ORDER BY. [DESC] Specifies a descending order for the query results.
To order by descending, do this:
SELECT TOP 6 * FROM Widereceivers ORDER BY yards DESC;
To order by ascending, do this:
SELECT TOP 6 * FROM Widereceivers ORDER BY yards ASC;
Upvotes: 4
Reputation: 28154
It's not sorting by yardage because you haven't told it to sort by yardage.
select top 6 * from widereceivers order by yardage desc;
Upvotes: 4