-1

Trying to explain my Question: Say, Table A contains ID,Number,Location.

Table B contains Option 1,Option 2.


I want to write a single query that would select ID, Number & Option 1 from the Table A and Table B.

(At present I am doing something like:

SELECT ID FROM [A] SELECT Option 1 FROM [B]

)

4

1 回答 1

1

You do this:

SELECT A.ID, A.Number, B.Option1
FROM TableA as A, TableB as B 
WHERE A.id = B.id;

This Part sets an alias for the table so that you don't have type in the full table name all the time:

TableA as A
TableB as B

This part is the relationship between table A and B.

WHERE A.id = B.id;

Consider reading SQL table relationships http://net.tutsplus.com/tutorials/databases/sql-for-beginners-part-3-database-relationships/

于 2013-07-04T19:40:26.097 回答