473,788 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about relationships, inner joins and query results

I have a database that has 5 tables with relationships linking last
names, so in my report it shows results from each table based on
person.

My question is this: when I go to query the result, it only shows
results of people listed in all 5 tables.

Is there any way to see people in the results only if they have
listings in 2 or 3 of the 5 tables? Is it something to do with
relationships?

Thanks!

Cara

Nov 13 '05 #1
3 1420
Use outer joins

For example, open the query window, add the tables you're interested
in. Double-click on each of the relationship lines and select the
correct option. For example:

Three tables:
Header [ID, Name]
Details [ID, fkHeaderID, Name]
Details2 [ID, fkHeaderID, Name]

1 Header has many Details
1 Header has many Details2

SQL output to show all records in Header and only records in Details
and Details2 where Header and a foreign keys in each many-side match:

SELECT Header.Name, Details.Name, Details2.Name FROM (Header LEFT JOIN
Details ON Header.ID = Details.fkHeade rID) LEFT JOIN Details2 ON
Header.ID = Details2.fkHead erID;

Access should produce this statement for you.

Thanks,
Johnny

Nov 13 '05 #2
I've got the left join working, but the issue now is, the information
will be entered into the tables randomly. IE, someone might enter
information into table 2 but they don't have corresponding information
in table 1 and thus it won't show up on my report page. Is there any
way to do a left and a right join? Or connect them all somehow?

Thanks

Nov 13 '05 #3
I will present two answers. The first is an abysmal hack,
but will do the job without a structure change. The second
is the right way to do it.

1. Build a view that includes ALL keys from all tables:
SELECT Key From Table1
UNION
SELECT Key from Table2
UNION
SELECT Key from Table3
....
Then use THIS view, and left join everything else to it.
The more data you have, the more inefficient this will be.

2. Redesign your database so that you have a Key table, then
use foreign keys to restrict the data that goes into the
other 5 tables so that only valid keys can be inserted.
Inserts to the Key table need to happen before data in the
other tables can be inserted.

Kevin
Cara<ro******** *@cox.net> 6/9/2005 9:48 AM >>>
I've got the left join working, but the issue now is, the
information
will be entered into the tables randomly. IE, someone
might enter
information into table 2 but they don't have corresponding
information
in table 1 and thus it won't show up on my report page.

Isthere any
way to do a left and a right join? Or connect them all
somehow?

Thanks

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6418
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, Employees.LastName, TerritoryID, Employees.EmployeeID, RegionID, ProductID from Employees
8
6325
by: kieran | last post by:
Hi, I have the following sql statement. I originally had the statement with two INNER JOINS but in some situations was getting an error so changed the last INNER JOIN to a LEFT OUTER JOIN (as is seem below). This seemed to work but i am unsure why and would like to know in case it falls over again. Why did the two INNER JOINS not work, and am I correct to use the LEFT OUTER JOIN in this context. As you can see the table 'tblStaff1_2'...
3
2050
by: Gary Wachs | last post by:
Hi folks, Lots of questions below. Thanks in advance for your help! 1. I go into the query expression builder, I show a lot (like 20 or 30) tables and queries, I create inner joins and left joins and so on, and build what winds up looking like a very complicated-looking QEB layout. I have been very deliberate and careful about structuring the tables and queries in the upper portion of the QEB so that it's easy to see how they all join...
5
4704
by: Mike Turco | last post by:
What is the difference between creating relationships in the front-end vs. the back-end database? I was trying to create a relationship in a database front-end and noticed that I could not check the referential integrity box. What gives? Continuing on with that line of thinking, I understand what do the relationships do for you in a database, but what do they do physically to the tables? Thanks,
7
2126
by: davegb | last post by:
I'm totally new to relational database design. My boss has asked me to create a database of information on the employees in our group. Seemed to me like a simple application to learn the ropes. A couple of things are confusing me. The first is "Relationships" and "Joins". Are they different names for the same thing? If not, what is the difference? I have a copy of the Access 2000 Bible, and it says, "When you create a relationship between...
6
9316
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: tblEmployees empId -- EmpName -- EmpRole -- EmpManager -------....------------.... ---------....--------------- 1........ dan yella..........1..........2
52
6356
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
8
2807
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table, I have a where clause which states : where PermitID like @WorkType order by WorkStart DESC
3
16507
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so all data from the separate tables is shown in a view (instead of the reference id's pointing to the separate tables...) I have some troubles formulating the SQL statement: I tried:
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10370
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9969
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
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 we have to send another system
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.