473,378 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

column functions

Hi all,

Do you know of any udb column functions resembling MS-Access "First" /
"Last" functions?

Regards,

tuarek

Apr 11 '06 #1
5 4005
tuarek wrote:
Hi all,

Do you know of any udb column functions resembling MS-Access "First" /
"Last" functions?

There are misc tricks.
If all you want is the MAX or MIN row use:
SELECT * FROM T ORDER BY X [ASC|DESC] FETCH FIRST ROW ONLY;
If you need the last/first per group you can use:

SELECT * FROM
(SELECT ROW_NUMBER() OVER(PARTITION BY group ORDER BY sort) AS rn, T.*
FROM T) AS X WHERE rn = 1;

If you need LAST and FIRST in the same row things are getting
progressively messier.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 11 '06 #2
"tuarek" <mb*******@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
Hi all,

Do you know of any udb column functions resembling MS-Access "First" /
"Last" functions?

Regards,

tuarek


You will get more responses if you explain what they do.
Apr 11 '06 #3
Thanks Serge...

Mark:

First & Last functions are aggregate functions like Min,MAX and SUM.
They return the first/last values from the result set returned by the
query.

For more information you can check:
http://office.microsoft.com/en-us/as...499571033.aspx

Regards,

Mehmet

Apr 11 '06 #4
tuarek wrote:
Thanks Serge...

Mark:

First & Last functions are aggregate functions like Min,MAX and SUM.
They return the first/last values from the result set returned by the
query.


The thing is that SQL is a set-oriented languages and the elements in a set
have - per definition - no order. So the terms "first" and "last" row are
completely meaningless, unless you impose a specific order in which the
rows are to be retrieved. And once you have such an order, the FETCH FIRST
n ROWS clause that Serge mentioned, should give you exactly what you want.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 11 '06 #5
WITH
Your_Query AS (
-- write your query
ORDER BY X, Y, Z
/* Depending on Remarks in your referenced site. without ORDER BY "....
the records returned by these functions will be arbitrary." So, it
would be better to specify ORDER BY */
)
SELECT Y.*
, (SELECTexpr FROM Your_Query ORDER BY X, Y, Z FETCH FIRST 1 ROWS
ONLY)
FROM Your_Query Y

Apr 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Demetris | last post by:
Hello there! I have a table (table1) and one of its columns DATA_X is CHAR(660) I will create another table (table2) similar to the above but i will replace the DATA_X column with several columns...
1
by: Milo Woodward | last post by:
I have some columns of data in SQL server that are of NVARCHAR(420) format but they are dates. The dates are in DD/MM/YY format. I want to be able to convert them to our accounting system format...
4
by: Peter Scott | last post by:
I created a table that has a column in that needs to contain a full Unix file path. Since 2048 was too long for a VARCHAR, I made it TEXT. I since populated the table. Now I want to make the...
11
by: csomberg | last post by:
SQL Server 2000 I will to compare a normal table with a replicated audit table having identical columns. I wish to report on the differences between the data. How can I loop though a "column...
2
by: Irfan Bondre | last post by:
When I try to create a table with a vargraphic column I get the following error. CREATE TABLE EIITEST.IRFAN ("VARC" VARCHAR (48) , "VARGRA" VARGRAPHIC (96) ) DATA CAPTURE NONE IN USERSPACE1;...
5
by: nimdez | last post by:
Hi, I am working on an existing code base in which a lot of data displayed to the user is formatted in tables. Most tables are printed row-by-row using printf() with "%s" print conversion...
1
by: neelu | last post by:
I have four columns in listview. SR Number Part# DES Qty Weight 59 9410106800 Nut 10 0.03 60 90304ge800 Helmet 5 0.325 61 9635439604 ...
11
by: surya | last post by:
hello sir, i have a table emp ,it has three fields one is empno int ,second is ename varchar(20). and last is salary , emp empno ename salary ----------- ------------...
1
by: feucos | last post by:
Hi all, I am new to these so plz never mind if this is funny. here is my problem : Table : moody Column : Title
2
by: Bernard Dhooghe | last post by:
The information center writes: "Encryption Algorithm: The internal encryption algorithm used is RC2 block cipher with padding, the 128-bit secret key is derived from the password using a MD2...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.