473,509 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Joins in Query

52 New Member
I have three tables. LP, TA and PR. I need to create a report that selects only those records in LP which have one or more matching records in either the TA or the PR table (or it could have multiple matches in both). I created a report with records from LP and two sub reports with records from TA and LP, but of course I get records that don't have entries in either table. I tried to create a query using joins, but it gave me an error message about an ambigous outer join. I tried to create a separate query and use that, as the error message said to do, but I can't seem to get anything to work. I finally created a make table query and an append query to select the matching records from one table and then append matching records from another and based the report on that new table and it works, but it is so clumsy and I need some additional reports so I don't want to continue that.

My fields that I'm working with are:
LP table
license number
Site name
City
ABC
and some other fields.

TA table
license number
Type
Consultant
Date Completed

PR table
license number
type
Scale
Consultant
Date Completed

I would be most appreciative of some help (in newbie language). I tried searching for other posts with "Joins" but I coudn't find anything that I could make work. Thanks so much.
Jun 18 '07 #1
5 1379
Rabbit
12,516 Recognized Expert Moderator MVP
I have three tables. LP, TA and PR. I need to create a report that selects only those records in LP which have one or more matching records in either the TA or the PR table (or it could have multiple matches in both). I created a report with records from LP and two sub reports with records from TA and LP, but of course I get records that don't have entries in either table. I tried to create a query using joins, but it gave me an error message about an ambigous outer join. I tried to create a separate query and use that, as the error message said to do, but I can't seem to get anything to work. I finally created a make table query and an append query to select the matching records from one table and then append matching records from another and based the report on that new table and it works, but it is so clumsy and I need some additional reports so I don't want to continue that.

My fields that I'm working with are:
LP table
license number
Site name
City
ABC
and some other fields.

TA table
license number
Type
Consultant
Date Completed

PR table
license number
type
Scale
Consultant
Date Completed

I would be most appreciative of some help (in newbie language). I tried searching for other posts with "Joins" but I coudn't find anything that I could make work. Thanks so much.
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT [LP Table].[License Number]
  2. FROM (([LP Table] INNER JOIN [TA Table] ON [LP Table].[License Number] = [TA Table].[License Number]) INNER JOIN [PR Table] ON [LP Table].[License Number] = [PR Table].[License Number]);
  3.  
Jun 18 '07 #2
CindySue
52 New Member
This seems to be selecting the records that have an entry in both tables, but not those that have an entry in only one table or the other as well. Also, it occurred to me that for my purposes it would be better to select from a query that is checking the date rather than the table. I am assuming I can substitute the query name for the table name? Thanks again so much for the help.
Jun 19 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT [LP Table].[License Number]
  2. FROM [LP Table] INNER JOIN [TA Table] ON [LP Table].[License Number] = [TA Table].[License Number]
  3. UNION
  4. SELECT DISTINCT [LP Table].[License Number]
  5. FROM [LP Table] INNER JOIN [PR Table] ON [LP Table].[License Number] = [PR Table].[License Number];
  6.  
Jun 19 '07 #4
CindySue
52 New Member
THAT SO WORKS!!! Thank you so very much! I can't tell you how wonderful it is to have someone willing to help.
Jun 19 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
THAT SO WORKS!!! Thank you so very much! I can't tell you how wonderful it is to have someone willing to help.
Not a problem, good luck.

And I missed your question the first time around but yes, you can use query names instead of table names.
Jun 19 '07 #6

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

Similar topics

6
2071
by: jgalzic | last post by:
Hi, I'm having trouble doing joins correctly on two tables. I've read up a lot about the different types of joins and tried lots of variations on inner, outer, and left joins with no avail....
3
6402
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
4
3975
by: Sri | last post by:
I am writing a download process in which i have a condition where i need to join four tables. Each table have lot of data say around 300000 recs. my question is when i am doing the joins on...
4
4090
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
7
31537
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
1
330
by: Lumpierbritches | last post by:
I'm trying to pull all the parents of a particular animal and I have my SQL statement that says not supported and when I attempt to run the Query, I get The SQL statement couldn't be executed...
4
1562
by: Brian Parker | last post by:
I'm new to ms-sqlserver ( 2000 ) and need to get an OUTER JOIN working on a three table query. Assumptions: -- I have events in the Event table. -- Each event CAN have one Transaction, but it's...
2
1609
by: gkellymail | last post by:
the following query works fine: select link.idx, link.x_table, link.x_id_a, link.x_id_z, a.strandid, b.strandid from link_detail, link, strand A, strand B where link_detail.x_table =...
9
11908
by: shapper | last post by:
Hello, I am used to SQL but I am starting to use LINQ. How can I create Left, Right and Inner joins in LINQ? How to distinguish the different joins? Here is a great SQL example:...
36
2461
by: TC | last post by:
I've used Access for many years. Several times, I've encountered a bug which I refer to as the "Vanishing Joins" bug. When it happens, joins vanish randomly from queries. More specifically, all...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7416
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...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.