SunQuest
           DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old November 23rd, 2007, 08:44 AM
Ingres Ingres is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 5 Ingres User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 33 sec
Reputation Power: 0
Inner join without keys

Hello,

I have two tables to join. I will use inner join as

SELECT * FROM T1 X INNER JOIN T2 Y
ON X.C1=Y.C1
WHERE X.C2>12;


Problem is key of the first table is the combinatin of three fields of another.

$left_table_id = $right_table_id1 . $right_table_id2 . $right_table_id3

I am not sore how to do this in query. It has to be something like that

SELECT * FROM T1 X INNER JOIN T2 Y
ON X.C1=Y.D1 . Y.D2 . Y.D3
WHERE X.C2>12;


Any opinion?

Reply With Quote
  #2  
Old November 23rd, 2007, 09:06 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,762 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 4 h 29 m 45 sec
Reputation Power: 37
Code:
 ON X.C1 = Y.D1 || Y.D2 || Y.D3


will work if all columns are of character type, otherwise you have to cast to character varying before doing the concatenation.

Reply With Quote
  #3  
Old November 23rd, 2007, 09:52 AM
Ingres Ingres is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 5 Ingres User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by swampBoogie
Code:
 ON X.C1 = Y.D1 || Y.D2 || Y.D3

This seems very promising but I get that
Code:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [IBM][Client Access Express ODBC Driver (32-bit)][DB2/400 SQL]SQL0199 - Keyword ON not expected. Valid tokens: ( END SET CALL DROP FREE LOCK OPEN WITH ALTER BEGIN CLOSE FETCH., SQL state 37000 in SQLExecDirect in ...


Can you give a hint about character varying? One field is varchar and others are int

Reply With Quote
  #4  
Old November 23rd, 2007, 10:22 AM
Ingres Ingres is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 5 Ingres User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 33 sec
Reputation Power: 0
It was my mistake. A typo broke the code.

It works, thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > Inner join without keys


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway