tags:

views:

172

answers:

4

see above...

+5  A: 

What you are asking is called NATURAL JOIN in relational terminology. Some database servers support this clause. I would prefer to manually specify the join expression even if the provider supports such a clause like:

SELECT .... FROM Table1 JOIN Table2 ON Table1.JoinCol = Table2.JoinCol ...
Mehrdad Afshari
As an addition to your point, I always specify the table or alias for the table so anyone looking will know exactly where the column comes from. It makes refactoring / maintenance much easier later on.
StingyJack
+8  A: 

Use an Alias for the table names is the shortest.

SELECT a.*, b.*
FROM table1 as 'a'
  INNER JOIN table2 as 'b'
    ON a.col1 = b.col1

You can also specify the full table names.

SELECT table1.*, table2.*
FROM table1
  INNER JOIN table2 
    ON table1.col1 = table2.col1
StingyJack
+4  A: 
select  *
from    Table1
        inner join
        Table2
        on Table1.ColumnName = Table2.ColumnName

Simple really.

Garry Shutler
With someone who is obviously new, is it a good idea to encourage SELECT * ?
StingyJack
What else can you say without any hint of the schema?
Garry Shutler
I'd suggest "ColumnName" instead of Column, since Column is a keyword. Not that it matters in real SQL, just for example code.
Done. Thought I may as well.
Garry Shutler
A: 

And for completeness (depending on your DBMS) you could use "USING":

SELECT
    ...
FROM
    table_a
INNER JOIN
    table_b
USING
    (common_column);
Milen A. Radev