How to construct a query

S

Shannon

I have two tables.

TableA has fieldID, field1, field2 and
TableB has RecID, fieldID, fieldA, fieldB.

Now there is a one to many relationship between TableA and
TableB through fieldID field.

I want to be able to write a query that will list out all
records in TableB and place the fields from TableA as well.

For example, I want the results of the query to look like:

fieldA, fieldB, field1, field2 {where field1 and field2
are the corresponding values based upon whatever the
fieldID was in TableB}

Does this make sense? Does anyone know how to write a
query to do this?

Thanks!
 
J

JaRa

This will show all the records of TableB which have a Record in TableA
SELECT fieldA, fieldb, field1, field2 FROM TableB INNER JOIN TableA ON
TableB.fieldID=TableA.fieldID

This will show all the records of TableB regardless a record is available in
TableA if a record is available in TableA then it will add the extra
information field1 and field2
SELECT fieldA, fieldb, field1, field2 FROM TableB LEFT JOIN TableA ON
TableB.fieldID=TableA.fieldID

- Raoul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top