473,396 Members | 2,010 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,396 software developers and data experts.

joins

I have three tables;
Advisor, Referral and Action.
Advisor is linked to Referral in a one to many relationship. Advisor being the one.
Referral is linked to Action in a one to many relationship. Referral being the one.
If I run a query to find all the referrals and actions therefrom I only get the Referrals where there is data entered in the Action table.
How do I overcome this please?
Rob
Aug 6 '06 #1
1 1593
Ok, this will be long since I'm not exactly seeing what you want to do so I'll use my own example.

Table Fruits (Fs) with field Fruit(F) contains Oranges, Apples Grapes and Tomatos
Table Vegies(Vs) with field Vegie(V) contains Potatos, Carrots, Grapes and Tomatos

If I want only what is common between Fs and Vs, I make a query with Table Fs and Table Vs joined F - V using option 1 (double click the relationship line) INNER JOIN or equal join. Returns Grapes and Tomatos

If I want only Oranges and Apples (in Fruits but not in Vegies) I bring in Table Fs and Vs joining F --> V using option 2 (Left Join) and typing NOT NULL in the criteria of V

If I want only Potatos and Carrots, I bring in Table Fs and Vs joing F to V using option 3 (right join) and typing NOT NULL under F

If I want Grapes Tomatos Oranges and Apples I do the Left Join but without the NOT NULL

If I want Oranges Apples Potatos and Carrots, but not Grapes or Tomatos, it's more complicated and you have to use the SQL view of the query. The code is this
SELECT Fruits.Fruit, Vegies.Vegie
FROM Fruits LEFT JOIN Vegies ON Fruits.Fruit = Vegies.Vegie
WHERE (((Vegies.Vegie) Is Null))
UNION ALL
SELECT Fruits.Fruit, Vegies.Vegie
FROM Fruits RIGHT JOIN Vegies ON Fruits.Fruit = Vegies.Vegie
WHERE Fruits.Fruit is null;

The last Option would be a FULL OUTER JOIN that would return Grapes, Tomatos, Oranges, Apples, Potatos, and Carrots and again you need to use SQL only but is the same code with an INNER JOIN as follows:

Select Fruits.Fruit, Vegies.Vegie
From Fruits INNER JOIN Vegies ON Fruits.Fruit = Vegies.Vegie
UNION ALL
SELECT Fruits.Fruit, Vegies.Vegie
FROM Fruits LEFT JOIN Vegies ON Fruits.Fruit = Vegies.Vegie
WHERE (((Vegies.Vegie) Is Null))
UNION ALL
SELECT Fruits.Fruit, Vegies.Vegie
FROM Fruits RIGHT JOIN Vegies ON Fruits.Fruit = Vegies.Vegie
WHERE Fruits.Fruit is null;

Hope this helps
-Trevor
Aug 6 '06 #2

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

Similar topics

6
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
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
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...
1
by: Prem | last post by:
Hi All Database Gurus, I am trying to write code which will produce all the possible valid queries, given tables and join information for tables. Right now i am just trying to construct all the...
4
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...
4
by: michaelnewport | last post by:
Greetings, I like to write my inner joins as below, but someone at work tells me its not as 'performant' as using the 'inner join' statement. Is this true ? Is there a better way to write it...
7
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"...
2
by: narendra vuradi | last post by:
Hi I have a requirement where in i haev to convert the SQL from Oracle to the one which will run on the SQL server. in the Oracle Query i am doing multiple joins, between some 13 tables. and...
9
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.