Solved

limiting the # of rows in a query

Posted on 2002-04-26
7
142 Views
Last Modified: 2013-12-24
Hello and thanks in advance for looking at this.

I'd like to select the 10 most recent items added to my database table. I'd like to pick these 10 items by the date they were added to the db.

Each of these items has a title AND a category. I'd like to get the 10 results and then group them by their category names.

Any ideas as to how I can go about accomplishing this?

Peter Edd
0
Comment
Question by:peteredd
7 Comments
 

Expert Comment

by:dnacerny
ID: 6972516
1) Make sure you have a 'CREATED_ON' field in your table.  Populate this field when inserting with the sysdate (oracle) or Now() (access).  These also include time stamps so it will contain the date and time of the entry.

2) Perform a sub-query to order the data by your 'CREATED_ON' field - this will give you the most recent entries first.  With the outer query return the sub set of 10 rows and order it by the field you desire.  Here is an example:

select title, category
  from (
     select *
       from table
      order by created_on desc
        )
 where rownum < 11
order by title ;

Hope this helps!!
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6973245
Try this

select top 10 *
from your_table
order by date_create desc


hongjun
0
 

Author Comment

by:peteredd
ID: 6973407
Actually, the answer was a combination of the two replies received. I will look to split the points between you two and thank you both very much.
0
Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

 

Author Comment

by:peteredd
ID: 6973412
I am using SQL, not Oracle, here's what the query ended up looking like and it works great.

select title, category
 from (
    select top 10 *
    from table
    order by created_on desc
       )
order by category;

thanks again
0
 
LVL 1

Expert Comment

by:Computer101
ID: 6974150
Points reduced for split.  Now you can accept an experts comment as an answer.  After that, make another question in this topic area for the other expert.

Computer101
E-E Moderator
0
 
LVL 33

Accepted Solution

by:
hongjun earned 100 total points
ID: 6974340
peterdd, accept my comment here and then post another question with the same points (100) in this Topic Area. Information of the thread will be like this
Subject: points for dnacerny
Points: 100
Body of Question: thanks for your help in http://www.experts-exchange.com/jsp/qShow.jsp?qid=20294076



hongjun
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6975215
-1 userid problem fixed, points moved to hongjun.
Moondancer - EE Moderator
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now