Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: Alternative to "First" function?

Tags:

sql

sas

I'm trying to write a query I don't want to have Cartesian products on. I was going to use the First function, because some Type_Codes have multiple descriptions, and I don't want to multiply my dollars.

Select
 Sum(A.Dollar) as Dollars,
 A.Type_Code,
 First(B.Type_Description) as FstTypeDescr
From
 Totals A,
 TypDesc B
Where
 A.Type_Code = B.Type_Code
Group by A.Type_Code

I just want to grab ANY of the descriptions for a given code (I don't really care which one). I get the following error when trying to use FIRST:

[IBM][CLI Driver][DB2/AIX64] SQL0440N  No authorized routine named "FIRST" of type "FUNCTION"

Is there another way to do this?

like image 544
Dan Avatar asked Jan 23 '23 06:01

Dan


1 Answers

Instead of First(), use MIN().

like image 50
recursive Avatar answered Jan 31 '23 11:01

recursive