Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

limiting the # of rows in a query

Posted on 2002-04-26
7
Medium Priority
?
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 

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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 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