Results 1 to 6 of 6

Thread: DB2 Query

  1. #1
    Join Date
    Dec 2003
    Posts
    4

    Unanswered: DB2 Query

    The following query is not working in DB2 v 6 on OS/390 . How this can be achieved without creating a view. I would like to receive the min value from two tables.

    SELECT MIN(VAL1) AS VAL2 FROM (
    ( SELECT MIN(COL1) AS VAL1
    FROM TABLE1
    )
    UNION
    ( SELECT MIN(COL1) AS VAL1
    FROM TABLE2
    ) )

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: DB2 Query

    Providing the error messages will be helpful

    Cheers
    Sathyaram

    Originally posted by suren
    The following query is not working in DB2 v 6 on OS/390 . How this can be achieved without creating a view. I would like to receive the min value from two tables.

    SELECT MIN(VAL1) AS VAL2 FROM (
    ( SELECT MIN(COL1) AS VAL1
    FROM TABLE1
    )
    UNION
    ( SELECT MIN(COL1) AS VAL1
    FROM TABLE2
    ) )
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Dec 2003
    Posts
    4

    Re: DB2 Query

    Originally posted by sathyaram_s
    Providing the error messages will be helpful

    Cheers
    Sathyaram
    The error message is

    SQL error at or before <EMPTY> (line 5, position 8). ) UNION

    When I remove the parenthesis for inner selects it gives

    SQL error at or before UNION

  4. #4
    Join Date
    Dec 2003
    Posts
    4

    Re: DB2 Query

    Hi,
    You may try a SQL statment like this:

    SELECT MIN(VAL1) AS VAL2 FROM
    (
    SELECT MIN(COL1) AS VAL1
    FROM TABLE1
    UNION
    SELECT MIN(COL1) AS VAL1
    FROM TABLE2
    ) as T1


    Originally posted by suren
    The error message is

    SQL error at or before <EMPTY> (line 5, position 8). ) UNION

    When I remove the parenthesis for inner selects it gives

    SQL error at or before UNION
    Last edited by Lin; 12-25-03 at 00:01.

  5. #5
    Join Date
    May 2003
    Location
    San Juan, PR
    Posts
    18
    Also, you can try next statement

    SELECT CASE WHEN A < B THEN A ELSE B END
    FROM (SELECT MIN(col1) A FROM table1) AS T1,
    (SELECT MIN(col2) B FROM table2) AS T2

    Saludos, Aloz

  6. #6
    Join Date
    Dec 2003
    Posts
    4
    Hi Aloz

    The query with case structure really works. That's Great !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •