All Forums Database
knip 2 posts Joined 03/11
25 Sep 2012
Experts Need Help!!!

I have a table   T1
with below data

A            B         C
100      10         1
200      20         2
 
And table T2 with
1   malaysia
2   India
10   Indonesia
20   srilanka
 
Result table should be as below with numbers replaced with corresponding descriptions
 
A            B                     C
100      Indonesia        malaysia
200      srilanka            India
 
 
 
 
 

Qaisar Kiani 337 posts Joined 11/05
25 Sep 2012

Here you go...

CREATE TABLE T1(A INTEGER,            B INTEGER,        C INTEGER) PRIMARY INDEX (A);
INSERT INTO T1(100,10,1);
INSERT INTO T1(200,20,2);

CREATE TABLE T2(ID INTEGER,            NAME VARCHAR(10)) PRIMARY INDEX (ID);
INSERT INTO T2(1, 'Malaysia');
INSERT INTO T2(2, 'India');
INSERT INTO T2(10, 'Indonesia');
INSERT INTO T2(20, 'Srilanka');


SELECT T1.A, T2_1.NAME, T2_2.NAME
FROM T1
INNER JOIN T2 T2_1
ON T1.B = T2_1.ID
INNER JOIN T2 T2_2
ON T1.C = T2_2.ID;
You must sign in to leave a comment.