Question:
Simple SQL statement help needed?
yeoys2003
2009-06-15 07:23:56 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!!
Three answers:
Germann A
2009-06-15 07:32:57 UTC
How is your SQL "is not logically right"?

It WILL give you the last order by ID in desc order distinct categories names...

This (to me) looks exactly what you described, but I can not be sure...
2009-06-15 07:46:38 UTC
You don't indicate which flavor of SQL you are using.



MySQL:

select CATEGORY from TABLE order by ID desc LIMIT 4 group by CATEGORY



Transact-SQL:

select top 4 CATEGORY from TABLE order by ID desc group by CATEGORY
mcwilliams
2016-10-31 06:21:46 UTC
replace table_name set discount_rt = '0.02' the place order_num like '%1354%'; i don't fairly comprehend the full element approximately 'for all products ordered as part of Order quantity 1354'. Assuming it meant - all products the place order quantity has part of its information containing 1354. wish this enables. good luck.


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