473,657 Members | 2,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Left Join with criteria (long msg)

Good day all,

I have a large outer joined query that I want to have some criteria.
The select query is gathering all part numbers from tblPartNumbers,
left joining to tblPartNumberVe ndor (since more than one vendor can
make the part), then left joining to tblPartNumberSu pplier (since more
than one supplier can distribute the vendor's part), then left joining
to tblPartNumberCo st (since more than one cost can be associated with a
single supplier if there are pricebreaks). Now, each of these have a
field named fldPrimary. I want to limit this join to only show the
primary vendor, primary supplier for the primary vendor and the primary
cost for the primary supplier, but if there is no entry for the part
number to still show the part number. Here is my current working SQL
statement:

SELECT tblPartNumber.P artNumberID, tblPartNumber.f ldPartNumber,
tblPartNumber.f ldDescription, tblPartNumberVe ndor.VendorID,
tblPartNumberVe ndor.fldPartNum berVendor,
tblPartNumberSu pplier.Supplier ID,
tblPartNumberSu pplier.fldPartN umberSupplier,
tblPartNumberCo st.fldUnits, tblPartNumberCo st.fldCostCDN,
tblPartNumberCo st.fldCostUS
FROM (tblPartNumber LEFT JOIN tblPartNumberVe ndor ON
tblPartNumber.P artNumberID = tblPartNumberVe ndor.PartNumber ID) LEFT
JOIN (tblPartNumberS upplier LEFT JOIN tblPartNumberCo st ON
tblPartNumberSu pplier.PartNumb erSupplierID =
tblPartNumberCo st.PartNumberSu pplierID) ON
tblPartNumberVe ndor.PartNumber VendorID =
tblPartNumberSu pplier.PartNumb erVendorID;

I tried adding AND criteria within each left join like this:

SELECT tblPartNumber.P artNumberID, tblPartNumber.f ldPartNumber,
tblPartNumber.f ldDescription, tblPartNumberVe ndor.VendorID,
tblPartNumberVe ndor.fldPartNum berVendor,
tblPartNumberSu pplier.Supplier ID,
tblPartNumberSu pplier.fldPartN umberSupplier,
tblPartNumberCo st.fldUnits, tblPartNumberCo st.fldCostCDN,
tblPartNumberCo st.fldCostUS
FROM (tblPartNumber LEFT JOIN tblPartNumberVe ndor ON
(tblPartNumber. PartNumberID = tblPartNumberVe ndor.PartNumber ID AND
tblPartNumberVe ndor.fldPrimary Vendor = yes)) LEFT JOIN
(tblPartNumberS upplier LEFT JOIN tblPartNumberCo st ON
(tblPartNumberS upplier.PartNum berSupplierID =
tblPartNumberCo st.PartNumberSu pplierID AND
tblPartNumberCo st.fldPrimaryCo st = yes)) ON
(tblPartNumberV endor.PartNumbe rVendorID =
tblPartNumberSu pplier.PartNumb erVendorID AND
tblPartNumberSu pplier.fldPrima rySupplier = yes);

But this still only returned a full outer join on each. I also tried
adding the criteria to the WHERE clause, but this demoted the outer
joins to inner joins. is there any way I can do this outer join in
access?

Thanks for the help and the time

Tim

Jun 25 '06 #1
2 3138
tr*****@gmail.c om wrote in
news:11******** **************@ c74g2000cwc.goo glegroups.com:
Good day all,

I have a large outer joined query that I want to have some
criteria. The select query is gathering all part numbers from
tblPartNumbers, left joining to tblPartNumberVe ndor (since
more than one vendor can make the part), then left joining to
tblPartNumberSu pplier (since more than one supplier can
distribute the vendor's part), then left joining to
tblPartNumberCo st (since more than one cost can be associated
with a single supplier if there are pricebreaks). Now, each of
these have a field named fldPrimary. I want to limit this join
to only show the primary vendor, primary supplier for the
primary vendor and the primary cost for the primary supplier,
but if there is no entry for the part number to still show the
part number. Here is my current working SQL statement:

SELECT tblPartNumber.P artNumberID,
tblPartNumber.f ldPartNumber, tblPartNumber.f ldDescription,
tblPartNumberVe ndor.VendorID,
tblPartNumberVe ndor.fldPartNum berVendor,
tblPartNumberSu pplier.Supplier ID,
tblPartNumberSu pplier.fldPartN umberSupplier,
tblPartNumberCo st.fldUnits, tblPartNumberCo st.fldCostCDN,
tblPartNumberCo st.fldCostUS FROM (tblPartNumber LEFT JOIN
tblPartNumberVe ndor ON tblPartNumber.P artNumberID =
tblPartNumberVe ndor.PartNumber ID) LEFT JOIN
(tblPartNumberS upplier LEFT JOIN tblPartNumberCo st ON
tblPartNumberSu pplier.PartNumb erSupplierID =
tblPartNumberCo st.PartNumberSu pplierID) ON
tblPartNumberVe ndor.PartNumber VendorID =
tblPartNumberSu pplier.PartNumb erVendorID;

I tried adding AND criteria within each left join like this:

SELECT tblPartNumber.P artNumberID,
tblPartNumber.f ldPartNumber, tblPartNumber.f ldDescription,
tblPartNumberVe ndor.VendorID,
tblPartNumberVe ndor.fldPartNum berVendor,
tblPartNumberSu pplier.Supplier ID,
tblPartNumberSu pplier.fldPartN umberSupplier,
tblPartNumberCo st.fldUnits, tblPartNumberCo st.fldCostCDN,
tblPartNumberCo st.fldCostUS FROM (tblPartNumber LEFT JOIN
tblPartNumberVe ndor ON (tblPartNumber. PartNumberID =
tblPartNumberVe ndor.PartNumber ID AND
tblPartNumberVe ndor.fldPrimary Vendor = yes)) LEFT JOIN
(tblPartNumberS upplier LEFT JOIN tblPartNumberCo st ON
(tblPartNumberS upplier.PartNum berSupplierID =
tblPartNumberCo st.PartNumberSu pplierID AND
tblPartNumberCo st.fldPrimaryCo st = yes)) ON
(tblPartNumberV endor.PartNumbe rVendorID =
tblPartNumberSu pplier.PartNumb erVendorID AND
tblPartNumberSu pplier.fldPrima rySupplier = yes);

But this still only returned a full outer join on each. I also
tried adding the criteria to the WHERE clause, but this
demoted the outer joins to inner joins. is there any way I can
do this outer join in access?

Thanks for the help and the time

Tim

Yes. You have to add the where clause to return where the field
is null. So starting from your first example

WHERE
(
tblPartNumberVe ndor.fldPrimary is TRUE
OR
tblPartNumberVe ndor.fldPrimary is NULL
)
AND
(
tblPartNumberSu pplier.fld primary is TRUE
OR
tblPartNumberSu pplier.fld primary is NULL
)
AND
(
tblPartNumberCo st.fld primary is NULL
OR
tblPartNumberCo st.fld primary is NULL
)
The nesting of OR inside AND is very important.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jun 25 '06 #2
Right On!! That did the trick. Thank you very much for the help

Tim

Bob Quintal wrote:
tr*****@gmail.c om wrote in
news:11******** **************@ c74g2000cwc.goo glegroups.com:
Good day all,

I have a large outer joined query that I want to have some
criteria. The select query is gathering all part numbers from
tblPartNumbers, left joining to tblPartNumberVe ndor (since
more than one vendor can make the part), then left joining to
tblPartNumberSu pplier (since more than one supplier can
distribute the vendor's part), then left joining to
tblPartNumberCo st (since more than one cost can be associated
with a single supplier if there are pricebreaks). Now, each of
these have a field named fldPrimary. I want to limit this join
to only show the primary vendor, primary supplier for the
primary vendor and the primary cost for the primary supplier,
but if there is no entry for the part number to still show the
part number. Here is my current working SQL statement:

SELECT tblPartNumber.P artNumberID,
tblPartNumber.f ldPartNumber, tblPartNumber.f ldDescription,
tblPartNumberVe ndor.VendorID,
tblPartNumberVe ndor.fldPartNum berVendor,
tblPartNumberSu pplier.Supplier ID,
tblPartNumberSu pplier.fldPartN umberSupplier,
tblPartNumberCo st.fldUnits, tblPartNumberCo st.fldCostCDN,
tblPartNumberCo st.fldCostUS FROM (tblPartNumber LEFT JOIN
tblPartNumberVe ndor ON tblPartNumber.P artNumberID =
tblPartNumberVe ndor.PartNumber ID) LEFT JOIN
(tblPartNumberS upplier LEFT JOIN tblPartNumberCo st ON
tblPartNumberSu pplier.PartNumb erSupplierID =
tblPartNumberCo st.PartNumberSu pplierID) ON
tblPartNumberVe ndor.PartNumber VendorID =
tblPartNumberSu pplier.PartNumb erVendorID;

I tried adding AND criteria within each left join like this:

SELECT tblPartNumber.P artNumberID,
tblPartNumber.f ldPartNumber, tblPartNumber.f ldDescription,
tblPartNumberVe ndor.VendorID,
tblPartNumberVe ndor.fldPartNum berVendor,
tblPartNumberSu pplier.Supplier ID,
tblPartNumberSu pplier.fldPartN umberSupplier,
tblPartNumberCo st.fldUnits, tblPartNumberCo st.fldCostCDN,
tblPartNumberCo st.fldCostUS FROM (tblPartNumber LEFT JOIN
tblPartNumberVe ndor ON (tblPartNumber. PartNumberID =
tblPartNumberVe ndor.PartNumber ID AND
tblPartNumberVe ndor.fldPrimary Vendor = yes)) LEFT JOIN
(tblPartNumberS upplier LEFT JOIN tblPartNumberCo st ON
(tblPartNumberS upplier.PartNum berSupplierID =
tblPartNumberCo st.PartNumberSu pplierID AND
tblPartNumberCo st.fldPrimaryCo st = yes)) ON
(tblPartNumberV endor.PartNumbe rVendorID =
tblPartNumberSu pplier.PartNumb erVendorID AND
tblPartNumberSu pplier.fldPrima rySupplier = yes);

But this still only returned a full outer join on each. I also
tried adding the criteria to the WHERE clause, but this
demoted the outer joins to inner joins. is there any way I can
do this outer join in access?

Thanks for the help and the time

Tim

Yes. You have to add the where clause to return where the field
is null. So starting from your first example

WHERE
(
tblPartNumberVe ndor.fldPrimary is TRUE
OR
tblPartNumberVe ndor.fldPrimary is NULL
)
AND
(
tblPartNumberSu pplier.fld primary is TRUE
OR
tblPartNumberSu pplier.fld primary is NULL
)
AND
(
tblPartNumberCo st.fld primary is NULL
OR
tblPartNumberCo st.fld primary is NULL
)
The nesting of OR inside AND is very important.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com


Jun 27 '06 #3

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

Similar topics

0
2445
by: Marek Lewczuk | last post by:
Hello, I have a strange problem, maybe some of you will be able to explain me something. I use LEFT JOIN as a substitute for subselects. It's true that many subselects can be rewriten using LEFT JOIN. I have made a query which use LEFT JOIN statement and... when there are many LEFT JOIN's (over 3) on the same table MySQL execute this query very long time... few hours or more. Maybe there is something wrong with my table structures... Are...
0
13002
by: Petre Agenbag | last post by:
Hi List Me again. I'm trying to return from multiple tables, the records that have field "information_sent" between two dates. The tables are all related by means of the id of the entry in the main table, ie.. main id entity_name ...
1
4209
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" slows the system down considerably. I've tried creating a temp db, but I can't figure out how to execute two select commands. (It throws the exception "The column prefix 'tempdb' does not match with a table name or alias name used in the query.")
7
31549
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" slows the system down considerably. I've tried creating a temp db, but I can't figure out how to execute two select commands. (It throws the exception "The column prefix 'tempdb' does not match with a table name or alias name used in the query.")
9
3204
by: Alan Lane | last post by:
Hello world: Background: Yesterday, January 21, Doug Steele was kind enough to help me out on a Left Join problem. I was trying to return all stores and their Gross Adds for December, 2004 (even though some of them had no Gross Adds for that month). My query would only show the non-zero GA stores. Doug stated "It's because of the Where clause. The stores which don't have any records for the period in question are being eliminated...
1
2868
by: Bob Alston | last post by:
I am trying to use an access sql statement in a module that does a left outer join on one table - joined to a table that has a selection criteria. The result is an inner join. If I do this in two pieces using queries, it works correctly. If I remove the criteria, it works correctly but of course gives me more matches than I want. Access 2003
5
4040
by: jason.evans | last post by:
Hi there. I am having an intrigueing problem. I have a query which left joins another query to itself twice. The original query is derived from a linked table in SQLServer 2000. When I run it on my pc It runs fine. However for other users in the office, it behaves as an inner join. ie it only returns the records fo which the join fields equal each other. This happens on every other pc
1
1921
by: aaron.reese | last post by:
Guys, this is my problem:- I have records which are linked by two fields on a left inner join (there may be 0,1 or more records in the right hand table) The relationship is not unique (it's a map reference so it can't be...) so I am getting a cartesian join on the right hand table - look, it's not my database OK, I don't have any choice!!!
11
19960
by: YZXIA | last post by:
Is there any difference between explicit inner join and implicit inner join Example of an explicit inner join: SELECT * FROM employee INNER JOIN department ON employee.DepartmentID = department.DepartmentID
0
8384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
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
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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
7314
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
4150
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...
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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.