Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Retrieving the 10 min entries from a database

Author  Topic 

zrizv
Starting Member

3 Posts

Posted - 2007-06-05 : 15:08:18
Hi, I've been trying to write an sql statement that can output the 10 minimum entries from a database, but I can't figure out how to do it.

Any help?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-06-05 : 15:17:42
you mean from a table not database.

select top 10 *
from yourTable
order by yourColumnWhichGivesYouTheMininumCondition desc

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

zrizv
Starting Member

3 Posts

Posted - 2007-06-05 : 15:28:15
sorry, table. And thanks, but that code doesn't seem to be working. If it helps, I'm using an old copy of Toad (version 6.3.11.1 g)

I've pasted the code I used below. The inside query works fine by itself, but when I try to run it with the top function I get this error: "ORA-00923: FROM keyword not found where expected" and it highlights the number 10

SQL:
select top 10 *
from (
select p.needle_rmc RMC,
round(avg(case when c.cpl < c.cpk then c.cpl else c.cpk end), 2) Cpk
from newcim.new_work_orders N, newcim.new_product_specs P, newcim.cpk c
where n.work_ord = c.work_ord
and n.item_cd = p.item_cd
and n.item_rev = p.item_rev
and n.start_date >= To_date('01/01/2007','MM/DD/YY')
and n.end_date <= To_date('06/04/2007','MM/DD/YY')
and n.work_ctr NOT LIKE 'SOT%'
group by p.needle_rmc
order by cpk
)
order by RMC
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-06-05 : 15:49:15
Your error indicates you are using Oracle. This is a MS SQL Server site, so our answers will be SQL Server specific.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-06-05 : 15:49:28
well i have no idea how oracle handles this...

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

zrizv
Starting Member

3 Posts

Posted - 2007-06-05 : 16:01:08
Oh,I thought they were the same thing. Sorry about that guys
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-06 : 09:50:46
Post your question at
www.OraFaq.com

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -