see above...
views:
172answers:
4
+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
2009-03-12 12:08:20
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
2009-03-12 12:13:24
+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
2009-03-12 12:08:50
+4
A:
select *
from Table1
inner join
Table2
on Table1.ColumnName = Table2.ColumnName
Simple really.
Garry Shutler
2009-03-12 12:09:29
With someone who is obviously new, is it a good idea to encourage SELECT * ?
StingyJack
2009-03-12 12:14:23
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
2009-03-12 12:27:41