Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Location
    Spain
    Posts
    7

    Question Unanswered: how to use joins

    Hy:

    I'm trying to execute this kind of sentences using jdbc and db2:

    SELECT * FROM SUBJECT SUB, SUSCRIPTOR SUS
    WHERE SUB.SUBJECT = SUS.SUBJECT

    The returned error is:

    Couldn't execute query:select * from SUBJECT SUB, SUSCRIPTOR SUS WHERE SUB.SUBJECT=SUS.SUBJECT
    COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0206N "SUB.SUBJECT" is not valid in the context where it is used. SQLSTATE=42703


    If I write:

    SELECT * FROM SUBJECT SUB, SUSCRIPTOR SUS
    WHERE SUB.'SUBJECT' = SUS.'SUBJECT'


    Couldn't execute query:select * from SUBJECT SUB, SUSCRIPTOR SUS WHERE SUB.'SUBJECT'=SUS.'SUBJECT'
    COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "'SUBJECT'" was found following "IPTOR SUS WHERE SUB.". Expected tokens may include: "<identifier>". SQLSTATE=42601


    but if I use:

    SELECT * FROM SUBJECT
    WHERE 'SUBJECT' = (SELECT 'SUBJECT' FROM SUSCRIPTOR)

    It works ok.

    Where is the problem?

  2. #2
    Join Date
    Feb 2004
    Posts
    24

    hi dobell

    SELECT * FROM SUBJECT SUB, SUSCRIPTOR SUS
    WHERE SUB.SUBJECT = SUS.SUBJECT

    couldn't work. the engine do not know what to give back !
    try:

    SELECT a.* FROM SUBJECT SUB a, SUSCRIPTOR SUS b
    WHERE a.SUBJECT = b.SUBJECT

    or vice versa.

    if want to see all from both tables try it with a union.

    hope this helps a bit !

    regards

    marc gaines

  3. #3
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    describe table SUBJECT

    and check if there is any column with the name SUBJECT in the table
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  4. #4
    Join Date
    Mar 2004
    Location
    Spain
    Posts
    7
    Hy:


    my table structure is:

    SUBJECT -----> (subject, user_id, date) subject is primary key

    SUSCRITOR---> (alias, subject, session_id, estado, date) alias, primary key

    If I execute my query in MySQL it works, but not in DB2

Posting Permissions

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