join multiple tables

A

Anonymous

Guest
how to join multiple tables in query?..i tried to use JOIN but it didnt function...n then i tried to use UNION but still didnt work and got the error like this:

"You have an error in your SQL syntax near 'UNION select DateInsert from MTbalance' at line 1

my query for the above error was:

"select DateInsert from MObalance UNION select DateInsert from MTbalance;"

pls anyone..help me..n thanks in advance
 
I would have to say just use an SQL tutorial e.g. http://www.w3schools.com/sql/sql_join.asp to find out about them as the examples are good.

As concerns your specific query "select DateInsert from MObalance UNION select DateInsert from MTbalance;" what is the semi-colon doing? other than that without seeing the table or what you are trying to do it is hard to properly advise you.... Your tables (I think) both have to be of the same structure for UNION to work too...

I find that the most useful method of joining tables is via the keys, for example:

Table 1 - PersonName:

owner_id (pk)
forename
surname

Table 2 - AddressJoin

owner_id (fk)
house_id (fk)

Table 3 - Address:

house_id (pk)
Addln1
Addln2
postcode

SQL: SELECT * FROM PersonName, AddressJoin, Address WHERE PersonName.owner_id = AddressJoin.owner_id AND AddressJoin.house_id = Address.house_id

You could narrow the search down further for example by adding AND PersonName.forename = Bob etc

If i've missed the topic, my apologies.
 
Or indeed if there is more than one person living in each house.... :D
 
Back
Top