What is the method for using 3rd table [Resolved]

Posted by Oswaldlily under Sql Server on 3/6/2014 | Points: 10 | Views : 1979 | Status : [Member] | Replies : 2
i have written query with 2 tables used..(no of rows 50)

now i need to use only one column from 3rd table ..

for this have to use join??

(Note: No of rows should be same as 50..just one column have to included from 3rd table)




Responses

Posted by: Bandi on: 3/6/2014 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Yes you have to do join with third table.... Your query also looking good..

As per ANSI standard you can make use of INNER JOIN as follows:

Select t1.Number,t1.Price,t1.code,t2.pkg,t3.data 
from Table1 t1
INNER JOIN Table t2 ON t1.code=t2.code
INNER JOIN Table3 t3 ON t3.code=t2.code


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 3/6/2014 [Member] Starter | Points: 25

Up
0
Down

Table1
Number Price code

Ao 100 a
B0 200 b
C0 300 c

Table2
pkg code

abc a
def b
ghi c

Table3
Number price code data

A1 50 a xyz
A2 50 a xyz
B1 100 b pqr
B2 100 b pqr
C1 150 c abc
C2 150 c abc

expected output
Number Price code pkg data
A0 100 a abc xyz
B0 200 b def pqr
C0 300 c ghi abc


Mine is cming as(wrong)

Number Price code pkg data
A0 100 a abc xyz
A0 100 a abc xyz
B0 200 b def pqr
B0 200 b def pqr
C0 300 c ghi abc
C0 300 c ghi abc

My query

Select t1.Number,t1.Price,t1.code,t2.pkg,t3.data from Table1 t1,Table t2,Table3 t3
where
t1.code=t2.code
and
t3.code=t2.code

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response