Deepak Kumar
Deepak Kumar

Reputation: 55

SQL join multiple table

I have 4 tables A, B, C, D

Table A:

 ct_no        ct_type
1010.           1
1011.           1
1012.           2
1013.           3

Table B:

ct_no.        jcode
1010.           4
1012.           3
1012.           4 
1013.           7
1013.           6
1013.           4

Table C:

Jcode          jname
4.                   ABC
3.                   lol
7.                   xyz

Table D:

filno         orno.     fildate.      ct_no
12017.      1.                           1010
12017.      2.                           1010
12017.      3.                           1012
42017.      1.                           1010

Now I want table d record with table c jname where table c jcode is 3

Output should be

filno   orno ctno  jnames
12017   1    1012  lol,ABC

Upvotes: 0

Views: 75

Answers (2)

Esperento57
Esperento57

Reputation: 17462

Try this:

select d.*, c.jname from tabled d 
inner join tableb b on d.ct_no=b.ct_no and b.Jcode=3
inner join tablec c on b.Jcode =c.Jcode

Upvotes: 1

Mureinik
Mureinik

Reputation: 311053

You need a couple of joins:

SELECT d.*
FROM   d
JOIN   b ON d.ct_no = b.ct_no
JOIN   c ON b.jcode = c.jcode
WHERE  c.jcode = 3

Upvotes: 1

Related Questions