473,399 Members | 4,192 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,399 software developers and data experts.

SQL - Left Join not working as intended

The following SQL does as I intend, but ...

SELECT offender_id, off_name, inv_ppo_id,
add_note, add_zip_id, it_name AS Purpose
FROM (offender INNER JOIN (investigation
INNER JOIN lu_investigation_type
ON investigation.inv_action_id =
lu_investigation_type.investigation_type_id)
ON offender.offender_id = investigation.inv_off_id)
LEFT JOIN address ON offender.offender_id = address.add_off_id
WHERE inv_ppo_id=[ID] AND inv_complete_date Is Null

When I add this AND clause, I only get the records that have a current
address; I no longer get all the records.

AND address.add_current=True;

What I want is all the records for the offenders - I just don't want
duplicates for more than one address.

How do I get this?
--
Darryl Kerkeslager
Nov 21 '05 #1
2 3944
If you use criteria on any field in the table on the outer side of the join,
you are limiting the result to the same as an inner join.

The simplest solution might be to stack 2 queries.
Create a query that returns the address fields you want, but only for the
current address:
SELECT offender_ID, Address, State, Zip FROM address WHERE
address.add_current = True

Then use that query as in input "table" for another query. With the outer
join, it should return all offenders, and only with their current addresses.

If one offender can have multiple current addresses, use GROUP BY in the
first query so it returns only one.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Darryl Kerkeslager" <ke*********@comcast.net> wrote in message
news:vs******************************@comcast.com. ..
The following SQL does as I intend, but ...

SELECT offender_id, off_name, inv_ppo_id,
add_note, add_zip_id, it_name AS Purpose
FROM (offender INNER JOIN (investigation
INNER JOIN lu_investigation_type
ON investigation.inv_action_id =
lu_investigation_type.investigation_type_id)
ON offender.offender_id = investigation.inv_off_id)
LEFT JOIN address ON offender.offender_id = address.add_off_id
WHERE inv_ppo_id=[ID] AND inv_complete_date Is Null

When I add this AND clause, I only get the records that have a current
address; I no longer get all the records.

AND address.add_current=True;

What I want is all the records for the offenders - I just don't want
duplicates for more than one address.

How do I get this?
--
Darryl Kerkeslager

Nov 21 '05 #2
"Allen Browne" <Al*********@SeeSig.Invalid> wrote
The simplest solution might be to stack 2 queries.


Thank you, Allen.

And thanks for the near-instant reply.

Wow.

--
Darryl Kerkeslager
Nov 21 '05 #3

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

Similar topics

2
by: Vector | last post by:
I have this working fine in Access and MSSQL. While trying to convert to MySQL the result is not what I'm looking for to get.. Two tables: T1 ---------------- ID1|cName |...
1
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"...
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"...
0
by: pj | last post by:
/* Make two tables, then find that a left join between them works, unless you add a view on top of one table -- if you add a view and use it, the left join fails -- rather, it acts as an inner join...
3
by: media.opslag | last post by:
Hi, How can i get this to work in access / jet sql ??? Someone?? SELECT tbl1., tbl2. FROM tbl1 left outer join tbl2 on
2
by: tricard | last post by:
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 tblPartNumberVendor (since...
0
by: yeahuh | last post by:
Quick and dirty version. Godaddy server using MySQL 4.0.24 I’m trying a left join to obtain id’s in table A(cars) that are NOT in car_id in table B(newspaper): *This is a cut down version...
4
by: phytorion | last post by:
i'm working in access2003 trying to bring three large tables(sys_sysobjects, sys_syscolumns, and dbo_pskeydefn) into one table filtered on by fieldname of a fourth table(table_name_master) ...
3
by: rrstudio2 | last post by:
If I have two tables and need to do a left outer join and include a where statement on the second table, it seems like the left outer join becomes an inner join. For example: Table: Names id...
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?
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
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
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...
0
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
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
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.