Jump to content

Calling SQL Experts : Nested Join 3 tables


k2s

Recommended Posts

Guys,

I am not an expert in SQL, and here trying to join 3 tables. 

table 1 has some 10+ columns - when i execute this i am able to see all 10 columns

table 2 & 3 are joined around 20 columns and when execute the query displays 20 columns 

now i want to join (table 1 and (table 2 and table 3) ) on certain condition. how do i do it ? 

 

calling @loveindia

Link to comment
Share on other sites

On SQL SERVER,

Select    T1.*,T2.*,T3.*

FROM table1    T1

JOIN table2 T2 on T1. Primarykey=T2.foreignkey

JOIN table3 T3 on T1.PrimaryKey=T3.foreinkey

Link to comment
Share on other sites

1 minute ago, RamGopalVarma said:

On SQL SERVER,

Select    T1.*,T2.*,T3.*

FROM table1    T1

JOIN table2 T2 on T1. Primarykey=T2.foreignkey

JOIN table3 T3 on T1.PrimaryKey=T3.foreinkey

First join table output emutundi?

Link to comment
Share on other sites

29 minutes ago, k2s said:

Guys,

I am not an expert in SQL, and here trying to join 3 tables. 

table 1 has some 10+ columns - when i execute this i am able to see all 10 columns

table 2 & 3 are joined around 20 columns and when execute the query displays 20 columns 

now i want to join (table 1 and (table 2 and table 3) ) on certain condition. how do i do it ? 

 

calling @loveindia

em question idi 2 tables in 3 tables in N tables ina you will join the same way dude...

Link to comment
Share on other sites

Just now, GunturMirchiBajji said:

em question idi 2 tables in 3 tables in N tables ina you will join the same way dude...

Konni examples na mohana padai

nenu join chesi chusthey ouput blank osthundi

Link to comment
Share on other sites

6 minutes ago, RamGopalVarma said:

On SQL SERVER,

Select    T1.*,T2.*,T3.*

FROM table1    T1

JOIN table2 T2 on T1. Primarykey=T2.foreignkey

JOIN table3 T3 on T1.PrimaryKey=T3.foreinkey

ila chesthey konni rows eguruthay ankunta ... i think u should use outer join .... anyways im not an expert so im not sure

Link to comment
Share on other sites

1 minute ago, k2s said:

Konni examples na mohana padai

nenu join chesi chusthey ouput blank osthundi

Select    T1.*,T2.*,T3.*

FROM table1    T1

JOIN table2 T2 on T1. Primarykey=T2.foreignkey

JOIN table3 T3 on T1.PrimaryKey=T3.foreinkey

 

idigo example. If you want all the records that match the join condition use inner join or else if you want all the records in the table that don't match the join condition use left outer join dude. Above example is doing inner join. 

Link to comment
Share on other sites

53 minutes ago, GunturMirchiBajji said:

Select    T1.*,T2.*,T3.*

FROM table1    T1

JOIN table2 T2 on T1. Primarykey=T2.foreignkey

JOIN table3 T3 on T1.PrimaryKey=T3.foreinkey

 

idigo example. If you want all the records that match the join condition use inner join or else if you want all the records in the table that don't match the join condition use left outer join dude. Above example is doing inner join. 

Got it... trying it now

Link to comment
Share on other sites

select t1.*,t.* from table1 t1,

(select t2.* , t3.* from table2 t2, table3 t3 where t2.table2_pk = t3.table_fk) t where t1.table1_pk = t.table1_fk

thumb rule joining n tables should have n-1 join conditions min

 

Link to comment
Share on other sites

2 minutes ago, hotmaddy said:

Going to classes now. Select Statements varaku ayyindi. Please wait for 4 more months and LTT this thread.

Vadule apatiki unkle implementation ayipoi, holidays kuda tesukuntu vuntadu

Link to comment
Share on other sites

1 minute ago, aatadista said:

Vadule apatiki unkle implementation ayipoi, holidays kuda tesukuntu vuntadu

Anduke uncle wait cheyyamantunna.

Link to comment
Share on other sites

4 hours ago, kiran karthik said:

select t1.*,t.* from table1 t1,

(select t2.* , t3.* from table2 t2, table3 t3 where t2.table2_pk = t3.table_fk) t where t1.table1_pk = t.table1_fk

thumb rule joining n tables should have n-1 join conditions min

 

why re , idhi nannu okadu interview lo adigadu..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...