Solved

limiting the # of rows in a query

Posted on 2002-04-26
7
170 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
Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

 

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

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…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 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