Join Syntax

  • HI,

     

    I wish to join two tables and produce a reult set that has all of the columns of each table. E.g.

    table1 has columns A,B,C,D and table2 has columns A, E, F, G

     

    How do I write the syntax that pulls all of the columns from each of the two tables?

     

    thanks,

     

    Paul

  • i'm not sure if this is just a simple join question or if there's some underlying complexity that i'm missing altogether...paul...you can set me straight...

    select t1.A, t1.B, t1.C, t1.D, t2.E, t2.F, t2.G from table1 t1

    inner join

    table2 t2

    on t1.A = t2.A

    edited....







    **ASCII stupid question, get a stupid ANSI !!!**

  • No complexity here !  I am just beginning sql queries and wanted to be sure of the correct syntax so that I can progress in the correct manner.

    Just a  join of two tables.

    I simply want to pull all the info from all the columns in table1 and table2 so that I can have one big result setwith the full contents of both tables.

    Question: If I am selecting everything from one table and everything from another, why can't I do "select * from table1 then a join - select * from table2 - bad syntax or simply won't work. ?

    Also, Forgive my beginnerness, but why do you have "on t1A = T2A" 

    Is this the column(s) on which the join takes place ?

    thanks Again.

    Paul

     

    thanks

  • This will answer most of your basic questions :

    http://www.w3schools.com/sql/default.asp

  • remi's sent you a great link...

    just want to answer your questions though -

    you could do a select * - except you will get your column A repeated twice in this case since both your tables have this column and you don't want to look at more information than you need to/must!

    I gave your table1 and table2 what is called an alias - this is for convenience only - to make the typing easier splly. when there are long table names and many joins involved - eg: if you had a table called tblThisIsMyVeryFirstTable - you give it an alias of tbl1 so you don't have to type this every single time and you also increase readability.

    lastly - the join always takes place on the columns that are common to the tables - so yes, if your table1 and table2 had column A (as you indicated) - then, that's where the join would take place.







    **ASCII stupid question, get a stupid ANSI !!!**

  • Of course this would assume that you would only want to see records where Value A was in both tables.  If You wish to see all of the records from Table1, then an outer join would apply.

  • Stay BASIC please .

  • Gomen Asai matemas! (Most humbly sorry! Nipponese)

  • NP... Don't wanna get into that when he doesn't know how to select .

  • nain gimon - badly written nipponese for - exactly the same reason as remi why i didn't go into this as well...







    **ASCII stupid question, get a stupid ANSI !!!**

  • Well I'll leave you all with that quote .

  • just don't quote me on it remi, is all...sayonara!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Ok Ok.

    Gomen-A-Sai  mattemasu

    (I'm Sorry)

    So it's been 34 years since I was in Japan! 

  • you know SLFine...things are difficult enough when we do this in English...why don't we just leave other languages out till we've got at least one mastered ?!?!







    **ASCII stupid question, get a stupid ANSI !!!**

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply