View previous topic :: View next topic
|
Author |
Message |
veera Warnings : 1 New User
Joined: 24 Nov 2004 Posts: 20 Location: chennai
|
|
|
|
[size=9][color=red]hello, friends
1. how to select first n max values from the perticular column.
plse give me query.
2. give me out rec syntax.
veerababu. |
|
Back to top |
|
|
jz1b0c
Active User
Joined: 25 Jan 2004 Posts: 160 Location: Toronto, Canada
|
|
|
|
veera wrote: |
[size=9][color=red]hello, friends
1. how to select first n max values from the perticular column.
plse give me query.
2. give me out rec syntax.
veerababu. |
VEERA, HERE IS THE ANSWER
SELECT "LOAN_NUM"
FROM TEST.LOAN
ORDER BY LOAN_NUM ASC
FETCH FIRST 4 ROWS ONLY ;
IF YOU ARE USING THIS IN A DB2 PROGRAM
USE OPTIMIZE CLAUSE IN DECLARE STATEMENT. |
|
Back to top |
|
|
ksivapradeep
New User
Joined: 30 Jul 2004 Posts: 95
|
|
|
|
hi jz1b0c,
veera asked the first height rows not the first n rows how to write that.ur query is correct but thats only to fetch first n rows.
regards,
siva pradeep |
|
Back to top |
|
|
jz1b0c
Active User
Joined: 25 Jan 2004 Posts: 160 Location: Toronto, Canada
|
|
|
|
veera wrote: |
[size=9][color=red]hello, friends
1. how to select first n max values from the perticular column.
plse give me query.
2. give me out rec syntax.
veerababu. |
" first n max values " This confused me. It should have been nth max value in a table. |
|
Back to top |
|
|
jz1b0c
Active User
Joined: 25 Jan 2004 Posts: 160 Location: Toronto, Canada
|
|
|
|
Veera,
Try this.
SELECT *
FROM TEST.TABLE1 T1
WHERE 5 = ( SELECT COUNT(DISTINCT T2.NUM)
FROM TEST.TABLE2 T2
WHERE T2.NUM >= T1.NUM)
ORDER BY NUM DESC ;;
tHIS WILL GIVE 5TH MAX |
|
Back to top |
|
|
|