SQL Select
20 pts.
0
Q:
SQL Select
Does anyone know of a way to use SQL (embedded) to select
only the 1st occurence of duplicate key records in a file.
I have a file where there may be duplicate keys and I need the 1st occurrence of the key as the data following the key is the data that is needed.
ASKED: Jan 17 2006  8:41 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
0 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
There are several ways to do this. If you just want to read the record, put FOR 1 RECORD ONLY at the end of the SELECT in DB2. In Oracle, use a WHERE clause of ROWNUM<2. You must use <2 and not =1. If you want to be able to modify the first record, a cursor can do it for you. This example is in DB2 SQL:

DECLARE myCursor CURSOR FOR
SELECT stuff
FROM table
WHERE conditions;

OPEN myCursor;

FETCH myCursor INTO :stuff;

UPDATE table
SET field = expression
WHERE CURRENT OF myCursor;

CLOSE myCursor;

--

Sheldon Linker (sol@linker.com)
Linker Systems, Inc. (www.linkersystems.com)
800-315-1174 (+1-949-552-1904)
Last Answered: Jan 17 2006  11:41 AM GMT by SheldonLinker   0 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



0