Question

I'm doing an assignment for class, and I'm at my whits end. Basically, I need to write a query that uses INNER JOIN's to combine all the data in 4 tables, while avoiding having titles columns with identical names (Ie Table1.Master_Number and Table2.Master_Number). The literal instructions are as follows:

Step 1: Create a view of all the columns (only list the columns once if the columns are duplicated in the tables) in all the tables of the Lecture 5 database. Save this query as Lecture_5_View and us this query to build the following 3 queries. In the “FROM” clause, you MUST use an “INNER JOIN” in this query. Remember ACCESS does not support the “CREATE VIEW” command so you must create a select query. `

Here is a screenshot of the database, that shows all the headings and column headings. Tables

Based on other posts like this, I thought that it would be pretty simple. I have this so far, but it does not want to run

(ie Syntax error(missing operator) in query expression 'Table1.Master_Number = Table2.Master_Number INNER JOIN Table4 ON Table1.Master_Number = Table4.Master_Number)

SELECT * 
FROM Table1
INNER JOIN Table2 ON Table1.Master_Number = Table2.Master_Number
INNER JOIN Table4 ON Table1.Master_Number = Table4.Master_Number

Where am I going wrong so far and how to I accomplish this query?

Much thanks, Josh

Was it helpful?

Solution

With Access you need to use parentheses when doing more than one join:

SELECT  * 
FROM    (Table1 
        INNER JOIN Table2 
            ON Table1.Master_Number = Table2.Master_Number)
        INNER JOIN Table4 
            ON Table1.Master_Number = Table4.Master_Number;

This is essentiall spliting down you query so you have at most one join per section, i.e. Your First query is:

SELECT  *
FROM    Table1
        INNER JOIN Table2
            ON Table1.Master_Number = Table2.Master_Number;

Then you have:

SELECT  *
FROM    YourFirstQuery
        INNER JOIN Table4 
            ON Table1.Master_Number = Table4.Master_Number;

This differs slightly from subqueries as you are still able to reference all fields from Table1 and Table2.


EDIT

To avoid duplicating columns you will need to explicitly list the columns you want (although you should be doing this anyway):

SELECT  Table1.Master_Number,
        Table1.Asset_Tag,
        Table1.Serial_Number,
        Table2.Last_Name,
        Table2.First_Name,
        Table4.Office_Number,
        Table4.Location,
        Table4.Department
FROM    (Table1 
        INNER JOIN Table2 
            ON Table1.Master_Number = Table2.Master_Number)
        INNER JOIN Table4 
            ON Table1.Master_Number = Table4.Master_Number;

OTHER TIPS

Try this:

  SELECT * FROM ((Table1
  INNER JOIN Table2 
  ON Table1.Master_Number = Table2.Master_Number)
  INNER JOIN Table4 
  ON Table1.Master_Number = Table4.Master_Number)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top