Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    25

    Unanswered: Not Exists Problem

    hi, i am using UDB 7 and i have the following 2 tables and valuesin my database.

    PRODUCT TABLE
    ProductNo,Prod_Name
    ----------
    1,LCD Monitor
    2, Printer

    INVENTORY TABLE
    InvenNo,Product
    -------------------
    1,2

    FOREIGN KEY (Product) REFERENCES PRODUCT(ProductNo)


    How do i select everything in Product table where ProductNo is NOT 2?

    I have tried Select * from Product Where Not Exists(Select * from Inventory Where Product =5). But nothing shows up. Can anyone help? Thanks

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: Not Exists Problem

    Originally posted by Shinto
    hi, i am using UDB 7 and i have the following 2 tables and valuesin my database.

    PRODUCT TABLE
    ProductNo,Prod_Name
    ----------
    1,LCD Monitor
    2, Printer

    INVENTORY TABLE
    InvenNo,Product
    -------------------
    1,2

    FOREIGN KEY (Product) REFERENCES PRODUCT(ProductNo)


    How do i select everything in Product table where ProductNo is NOT 2?
    Did you try this:

    SELECT * FROM PRODUCT WHERE PRODUCTNO <> 2

  3. #3
    Join Date
    Jan 2004
    Posts
    25

    Re: Not Exists Problem

    Originally posted by n_i
    Did you try this:

    SELECT * FROM PRODUCT WHERE PRODUCTNO <> 2

    I dont think <> works though. It keeps returning me a message stating > was unexpected at this time.

    I managed to solve my problem by using SELECT * FROM PRODUCT WHERE PRODUCTNO != 2

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: Not Exists Problem

    Originally posted by Shinto
    I dont think <> works though. It keeps returning me a message stating > was unexpected at this time.

    If you run the statement from the OS command line you'll need to enclose it in quotes, like this:

    db2 "SELECT * FROM PRODUCT WHERE PRODUCTNO <> 2"

Posting Permissions

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