Question:
Simple SQL statement help needed?
yeoys2003
2009-06-15 08:44:10 UTC
How do I write this SQL statement such that i could get that output?

"Getting the 4 latest categories of the latest updated news."

==SQL Table==
ID CATEGORY
76 Sports
75 Sports
74 Entertainment
73 Sports
72 Business
71 World
70 Business

==OUTPUT==
Sports
Entertainment
Business
World

There are still some more other data in the SQL Table such as news title, date etc.

I tried "Select distinct category order by id DESC" but it not is not logically right.

I just need the sql statement.

Any kind soul to help me?? thanks!!

=======================================

not logically right refers to it will get the distinct categories but from the bottom despite stating to arrange by ID.

==SQL Table==
76 Sports
.
.
.
6 Sports
5 Entertainment
4 Sports
3 Business
2 World
1 Business

==OUTPUT==
Entertainment
Sports
World
Business
Four answers:
Serge M
2009-06-15 14:59:43 UTC
select category from (

select category, max(id) mk from YourTable group by category

) x order by mk desc
davidcastro80
2009-06-15 08:57:57 UTC
SELECT TOP 4 From [tablename] order BY ID desc
sicilia
2016-10-31 06:42:37 UTC
you do not point out which style of sq. you're utilising. MySQL: decide on type from table order by utilising identity desc decrease 4 group by utilising type Transact-sq.: decide on precise 4 type from table order by utilising identity desc group by utilising type
sssss
2009-06-15 08:55:48 UTC
could u restate this question


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...