Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

db2 query to select the first row fetched

Tags:

select

db2

I have a query like

UPDATE PRD_PRODUCT_L10N ppl
 SET ( CATCHING_PHRASE
    , GENERIC_NAME
    , INGREDIENTS
    , QUANTITY
    , DOSE
    , NUTRITION_FACTS
    , PRODUCT_DESCRIPTION
    , PROMOTION_MESSAGE
    , MESSAGE
   ) = (
   SELECT distinct CATCHING_PHRASE
        , GENERIC_NAME
        , INGREDIENTS
        , QUANTITY
        , DOSE
        , NUTRITION_FACTS
        , PRODUCT_DESCRIPTION
        , PROMOTION_MESSAGE
        , MESSAGE
    FROM  TEMP_UPLOAD_PRODUCT_ATTRIBUTES tupa
    INNER JOIN
          PRD_PRODUCT                    pp
      ON  pp .EISIDENTIFIER = tupa.EISIDENTIFIER
    WHERE ppl.PRODUCTGUID   = pp.GUID
      AND ppl.LOCALEGUID     = tupa.LOCALEGUID
   )
 WHERE EXISTS (
   SELECT 0
    FROM  TEMP_UPLOAD_PRODUCT_ATTRIBUTES tupa
    INNER JOIN
          PRD_PRODUCT                    pp
      ON  pp .EISIDENTIFIER = tupa.EISIDENTIFIER
    WHERE ppl.PRODUCTGUID   = pp  .GUID
      AND ppl.LOCALEGUID     = tupa.LOCALEGUID
   )     

the subquery returns more than 1 row and I would like to insert the first selected. How do I do that in DB2 database?

Please advice.

Thanks

like image 223
beetri Avatar asked Feb 27 '12 22:02

beetri


1 Answers

Depending on your DB2 version (i think 8 upwards) you can use fetch at your subquery

(select * from table fetch first 1 rows only)

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2.doc.admin%2Ffrstnrw.htm

like image 115
Tadeu Maia Avatar answered Sep 23 '22 13:09

Tadeu Maia