AFDB_Andhagadu Posted June 8, 2013 Report Posted June 8, 2013 Bhayya's, I Have 3 tables. Table A Table B Table C Table A and Table B has a common column called Column_AB Table B and Table C has a common column called Column_BC But Table Table A and Table C doesn't have any common column.I need data from all the 3 tables(Table A,Table B,Table C) How to join the these 3 tables using SQL ? Please Help !!
pachimirchi Posted June 8, 2013 Report Posted June 8, 2013 A join B join C.. all 3 tbls info vastadi..
accuman Posted June 8, 2013 Report Posted June 8, 2013 idi vaadu [url="http://stackoverflow.com/questions/6414602/3-table-sql-join"]http://stackoverflow.com/questions/6414602/3-table-sql-join[/url]
accuman Posted June 8, 2013 Report Posted June 8, 2013 [size=3] [b] [url="http://stackoverflow.com/questions/6414602/3-table-sql-join"]3 table sql join[/url][/b] [/size][color=#000000][font=Arial,][size=3] [background=transparent] [center][background=transparent][url=""]up vote[/url][color=#555555][size=6][background=transparent]0[/background][/size][/color][url=""]down vote[/url][url="http://stackoverflow.com/questions/6414602/3-table-sql-join#"]favorite[/url] [/background][/center] [background=transparent] [size=4][background=transparent] [background=transparent] I need to join tableA, tableB, and tableC, but it's possible that tableB won't have a corresponding row. Posted below is how I am currently doing the query. The problem with it is that if tableB doesn't have a correspoinding row, it won't return a result. My sql skills are very rusty so I appreciate your help. Thanks.[/background] [color=#00008B][background=transparent]SELECT[/background][/color][background=transparent] [/background][background=transparent][[/background][color=#00008B][background=transparent]column[/background][/color][background=transparent] names[/background][background=transparent]][/background][background=transparent] [/background][color=#00008B][background=transparent]FROM[/background][/color][background=transparent] tableA [/background][color=#00008B][background=transparent]AS[/background][/color][background=transparent] a[/background][background=transparent],[/background][background=transparent] tableB [/background][color=#00008B][background=transparent]AS[/background][/color][background=transparent] b[/background][background=transparent],[/background][background=transparent] tableC [/background][color=#00008B][background=transparent]as[/background][/color][background=transparent] c [/background][color=#00008B][background=transparent]WHERE[/background][/color][background=transparent] b[/background][background=transparent].[/background][background=transparent]blah [/background][background=transparent]=[/background][background=transparent] a[/background][background=transparent].[/background][background=transparent]blah [/background][color=#00008B][background=transparent]AND[/background][/color][background=transparent] c[/background][background=transparent].[/background][background=transparent]foo [/background][background=transparent]=[/background][background=transparent] a[/background][background=transparent].[/background][background=transparent]foo [/background][color=#00008B][background=transparent]AND[/background][/color][background=transparent] [/background][background=transparent][[/background][background=transparent]more [/background][color=#00008B][background=transparent]where[/background][/color][background=transparent] conditions[/background][background=transparent]][/background] [/background][/size] [background=transparent] [url="http://stackoverflow.com/questions/tagged/sql"]sql[/url] [url="http://stackoverflow.com/questions/tagged/join"]join[/url][/background] [/background] [/background][/size][/font][/color]
rondon Posted June 8, 2013 Report Posted June 8, 2013 [size=4]with t1 as [/size] ( select 1 id , 'hari' name,123 ssn from dual union all select 2,'suman',234 from dual), t2 as( select 123 ssn, 'ab' city from dual union all select 234,'ny' from dual), t3 as ( select 'ab' city,'abudhabi' cityname from dual union all select 'ny','newyork' from dual) select table1.id,table1.name,table2.ssn,table3.cityname from t1 table1 inner join t2 table2 on table1.ssn=table2.ssn inner join t3 table3 on table2.city=table3.city
Recommended Posts