If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > how to use joins

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-12-04, 07:06
dobell dobell is offline
Registered User
 
Join Date: Mar 2004
Location: Spain
Posts: 7
Question 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?
Reply With Quote
  #2 (permalink)  
Old 05-12-04, 08:18
disaster disaster is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 05-12-04, 09:09
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
  #4 (permalink)  
Old 05-12-04, 10:21
dobell dobell is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On