473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SQL-fu failing as I attempt to Update using multiple joins

G'day all,
I'm trying to update a single table (containing plans for flights) with information from the same and other tables (containing info for organisations and locations).

tblFlightPlans contains the txt-column 'TripSummary', which is what I'm trying to update, as well as ID numbers for the origin, destination, and plane carrier (eg, Qantas). The SQL code below successfully joins tblLocations and tblFlightPlans and updates TripSummary with a text name for the flight's origin.
Expand|Select|Wrap|Line Numbers
  1. UPDATE [SELECT PlaceID, PlaceName FROM tblLocations]. AS test INNER JOIN tblFlightPlans ON test.PlaceID=tblFlightPlans.Leg1Origin SET TripSummary = test.PlaceName;
  2.  
What I need is something very similar, but involving the above TWICE (two lookups), for an origin and a destination, as well as a carrier. I've tried this, which fails:
Expand|Select|Wrap|Line Numbers
  1. UPDATE 
  2. [SELECT PlaceID, PlaceName FROM tblLocations]. AS Origins INNER JOIN tblFlightPlans ON Origins.PlaceID=tblFlightPlans.Leg1Origin
  3. [SELECT PlaceID, PlaceName FROM tblLocations]. AS Destinations INNER JOIN tblFlightPlans ON Destinations.PlaceID=tblFlightPlans.Leg1Dest
  4. [SELECT OrgID, Name FROM tblOrganisations]. AS Carriars INNER JOIN tblFlightPlans ON Carriars.OrgID=tblFlightPlans.Leg1OrgID
  5.  
  6. SET TripSummary = Origins.PlaceName & " to " & Destinations.PlaceName & " by " Carriars.Name; 
  7.  
...and also this, which also fails (though again, the singular form works, if I'm only trying to update TripSummary with one PlaceName):
Expand|Select|Wrap|Line Numbers
  1. UPDATE tblFlightPlans 
  2. INNER JOIN [SELECT PlaceID, PlaceName FROM tblLocations]. AS Origins ON Origins.PlaceID=tblFlightPlans.Leg1Origin 
  3. INNER JOIN [SELECT PlaceID, PlaceName FROM tblLocations]. AS Destinations ON Destinations.PlaceID=tblFlightPlans.Leg1Dest
  4. INNER JOIN [SELECT OrgID, Name FROM tblOrganisations]. AS Carriars ON Carriars.OrgID=tblFlightPlans.Leg1OrgID
  5.  
  6. SET TripSummary = Origins.PlaceName & " to " & Destinations.PlaceName & " by " Carriars.Name; 
  7.  
What am I doing wrong? How do I approach using multiple joins in Access?

If all else fails, is there some sort of "append" function that will allow me to make 3 separate queries and tack it on to the same textbox?

Notes:
Interchanging "(xxx) AS x" and "[xxx]. AS x" gives the same errors, so I don't think it's a bracketing problem. Also, "Carriars" is deliberate, the name "Carriers" is already taken somewhere else =P
Mar 10 '09 #1
3 2239
UPDATE: Apparrently there is such a thing as 'nested INNER JOINs'. Looking into these now, but they're pretty obtuse beasts.
Mar 10 '09 #2
UPDATE: Nevermind, all, got it sorted! =)
The following does what I want, ie, gives a text output of "Location1 to Location2 by Carrier1".

Expand|Select|Wrap|Line Numbers
  1. UPDATE 
  2. [SELECT PlaceID, PlaceName FROM tblLocations]. AS Origins INNER JOIN 
  3. (
  4. [SELECT PlaceID, PlaceName FROM tblLocations]. AS Destinations INNER JOIN 
  5. (
  6. tblFlightPlans INNER JOIN [SELECT OrgID, Name FROM tblOrganisations]. AS Carriars ON Carriars.OrgID=tblFlightPlans.Leg1OrgID
  7. ON Destinations.PlaceID=tblFlightPlans.Leg1Dest
  8. ON Origins.PlaceID=tblFlightPlans.Leg1Origin 
  9.  
  10. SET TripSummary = Origins.PlaceName & " to " & Destinations.PlaceName & " by " & Carriars.Name;
  11.  
Mar 10 '09 #3
NeoPa
32,556 Expert Mod 16PB
Just to assuage your curiosity about the subquery notation, see Access QueryDefs Mis-save Subquery SQL.

Note, in most cases (except those where it seems Access recognises that it was created by itself) only the version with parentheses will be recognised.
Mar 11 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Peter | last post by:
I run most of my SQL scripts via kornshell on AIX. I use the "here-document" to run some of the smaller ones. Example: #!/bin/ksh # Analyze the table. sqlplus...
1
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005...
4
by: Anns via SQLMonster.com | last post by:
My company currently has about 20-25 Ms Access Database that they want to replace the FE with .net and the BE on SQL. This will be done using Visual Studio 2005. Once the FE is converted to...
6
by: Fuzzydave | last post by:
I am back developing futher our Python/CGI based web application run by a Postgres DB and as per usual I am having some issues. It Involves a lot of Legacy code. All the actual SQL Querys are...
14
by: Developer | last post by:
Hello All, i have recently installed VS2005 and was trying to install SQL sever 2000. I have Win XP' SP2. But when I tried installing, it only installed client tools and not the database. Can...
11
by: HC | last post by:
I posted this in one of the VB forums but I'm starting to think it might be more appropriate to have it here, since it really seems to be a SQL server (MSDE/Express 2005) problem: Hey, all, I...
3
by: Steve | last post by:
Hi All I downloaded Sql server 2005 express SP2 and attempted to modify the Bootstrapper package files as I did with SP1 When i try to install SQL server as part of my VS 2005 deployment app I...
9
by: fniles | last post by:
I would like to copy a table(s) from SQL Server 2005 to a CVS file and vice versa. I was thinking to use the BCP command line utility, but I have a few questions: 1. The machine where I am...
7
by: Mike1961 | last post by:
Hi there. Well the situation is this, I have two tables: 1) tbl_registry where rows with code = 123 are 35 ; 1) tbl_Registered where rows with code = 123 are 43 In tbl_Registered I have...
2
Frinavale
by: Frinavale | last post by:
SQL Injection Attack A database is a collection of information organised in such a way that allows computer programs to access data (even large amounts) quickly and easily. Data within a database is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.