472,348 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

Is a LEFT JOIN with a subquery possible?

I have a list of towns in tblTownData, and a list of people's names in
tblNames. During a year, there are multiple events where more names are
added in tblNames, for a particular town.

ie:
TOWNID EVENTID NAME
1 1 John Doe
1 1 Jane Doe
1 2 Bell E. Dancer
1 2 Frank N. Furter

For each event, I am trying to give feedback to the user as to which towns
have not had a single name added yet. That is, I am trying to generate a
list of towns using a left join on a subquery.

In Access, I can create a query (tblCurrentNamesInTown):
SELECT tblNames.TownID
FROM tblNames
WHERE (((tblNames.ELECTIONID)=1))

then a new query (tblTownData Without Matching Current):
SELECT tblTownData.Municipality
FROM tblTownData LEFT JOIN tblCurrentNamesInTown ON tblTownData.TownID =
tblCurrentNamesInTown.TownID
WHERE (((tblCurrentNamesInTown.TownID) Is Null));

This will return my list fine.

However, I need to call this query result from the database using a SQL
statement inside an ASP page.

Can you create a LEFT JOIN to the subquery (tblCurrentNamesInTown)?
If so, can anyone help with the syntax?
Dave
Nov 13 '05 #1
3 22149

Dave wrote:
I have a list of towns in tblTownData, and a list of people's names in
tblNames. During a year, there are multiple events where more names are
added in tblNames, for a particular town.
...


Did you consider doing something simpler like:

SELECT Municipality FROM tblTownData WHERE TownID NOT IN (SELECT
DISTINCT TownID FROM tblNames WHERE EVENTID = 1);

Of course, if the number of records in tblNames is fairly large the
'NOT IN' syntax becomes inefficient and could explain the route you've
chosen.

James A. Fortune

Nov 13 '05 #2
Jim's suggestion is excellent. However, if you must use the join, you
can do the following:

SELECT tblTownData.Municipality
FROM tblTownData LEFT JOIN
(SELECT tblNames.TownID
FROM tblNames
WHERE (((tblNames.ELECTIONID)=1))) AS tblCurrentNamesInTown
ON tblTownData.TownID =
tblCurrentNamesInTown.TownID
WHERE (((tblCurrentNamesInTown.TownID) Is Null));

Bill E.
Hollywood, FL

Nov 13 '05 #3
>I have a list of towns in tblTownData, and a list of people's names in
tblNames. During a year, there are multiple events where more names are
added in tblNames, for a particular town.


James and Bill,

Thanks for the feedback. This seemed to work well. I'm next going to load
the database with roughly the same number of records as I would expect over
several events, and determine which way to go.

Thanks for saving my sanity!

Dave
Nov 13 '05 #4

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

Similar topics

6
by: Thomas Beutin | last post by:
Hi, i've a speed problem withe the following statement: SELECT DISTINCT pz.l1_id, pz.l2_id, pz.l3_id, pz.l4_id FROM ot_adresse AS a, ot_produkt...
7
by: stabbert | last post by:
I am attempting to join two tables together on two different unix servers. Here is some relevant info about the tables. TABLE 1 Setup ...
23
by: Brian | last post by:
Hello All - I am wondering if anyone has any thoughts on which is better from a performance perspective: a nested Select statement or an Inner...
7
by: deko | last post by:
SELECT tblTxAcct.TxAcctName, tblTxType.TxTypeName, Nz(qryTxAcctListCt.TxCount, 0) AS TxCt FROM (tblTxAcct INNER JOIN tblTxType ON...
14
by: Ryan | last post by:
I want to do the following SQL statement in Access. However, it won't allow me to have the secondary part of my join statement and tells me that...
14
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key...
2
by: lelandhuang | last post by:
I am developing reporting service and using lots of 'LEFT OUTER JOIN', I am worried about the performance and want to use some subquery to improve...
6
by: Avaenuha | last post by:
I need to use a left outer join to get all of one table, and match it to specific instances of another table. Eg, report all of A, and where A has...
4
by: polycom | last post by:
Assistance needed to optimize this query SELECT SD.content_id AS Id, SD.title AS Title, CT.name AS Contenttype,...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.