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
 Use of Least()

Author  Topic 

sarka
Starting Member

12 Posts

Posted - 2008-01-10 : 04:12:27
Hallo!

I've read a lot about this special function but I didn't get if I can use it with selections. For example, I have a table films(id, name, type, day, hour) that reports the timetable of a cinema. I'd like to select the last sciencefiction film (let's say type=kkk) of the day xx-yy-zz. How can I do?

Thank you!

nr
SQLTeam MVY

12543 Posts

Posted - 2008-01-10 : 04:14:09
select top 1 *
from films
where type = 'sciencefiction'
and day = 'yyyymmdd'
order by hour desc


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sarka
Starting Member

12 Posts

Posted - 2008-01-10 : 04:28:37
Hi. Thank you for your reply!
I didn't manage to run the script.
What is top? And 1?
If I delete 1 I have an error in where clause.
What should I do?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2008-01-10 : 04:50:02
Are you using sql server? Which version?
Did you include the * in select top 1 *


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sarka
Starting Member

12 Posts

Posted - 2008-01-10 : 04:52:57
Can the version be 10.2?
yes, I added the *. The error should be the 1.

Thanks!
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2008-01-10 : 05:04:03
>> Can the version be 10.2?
No - sounds more like Oracle. 10g release 2?

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sarka
Starting Member

12 Posts

Posted - 2008-01-10 : 05:11:33
yeah, it's oracle.
Go to Top of Page

sarka
Starting Member

12 Posts

Posted - 2008-01-10 : 06:01:24
Ok, I've read there's really a big syntax difference between different SQL languages. I've read that TOP is specifically for Microsoft SQL.
But what is the equivalent in ORACLE?
Go to Top of Page

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-01-10 : 06:16:10
read about ROW_NUMBER() in Oracle help

Go to Top of Page
   

- Advertisement -