473,387 Members | 1,790 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,387 software developers and data experts.

jet sql access subquery in from clause left outer join does not work ... help!!

Hi,

How can i get this to work in access / jet sql ??? Someone??

SELECT
tbl1.[field],
tbl2.[otherfield]

FROM [Table1] tbl1
left outer join [Table2] tbl2 on
tbl2.[id1] = tbl1.[id1] and
tbl2.[id2] = tbl1.[id2] and
tbl2.[somefield] =
(
SELECT MAX([somefield])
FROM [Table2] tbl2_temp
WHERE tbl2_temp.[id1] = tbl1.[id1] and
tbl2_temp.[id2] = tbl1.[id2]
)

It seems access doesn't have the possibility to put subqueries in from
clauses - left outer joins...

Thanx!
Gene.

Mar 23 '06 #1
3 6617
<me**********@gmail.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
Hi,

How can i get this to work in access / jet sql ??? Someone??

SELECT
tbl1.[field],
tbl2.[otherfield]

FROM [Table1] tbl1
left outer join [Table2] tbl2 on
tbl2.[id1] = tbl1.[id1] and
tbl2.[id2] = tbl1.[id2] and
tbl2.[somefield] =
(
SELECT MAX([somefield])
FROM [Table2] tbl2_temp
WHERE tbl2_temp.[id1] = tbl1.[id1] and
tbl2_temp.[id2] = tbl1.[id2]
)

It seems access doesn't have the possibility to put subqueries in from
clauses - left outer joins...

Thanx!
Gene.



I'm not sure your intention is quite clear. You have a left join in the
first bit, so you want to show all the values in Table1 regardless of
whether you get a match (based on the two id's) in the other table. On the
other hand, you have want the somefield to be equal to the max, which would
imply there was already a match with the ids.

If you are working from Access (as opposed to using a Jet database with some
other software), you could always create multiple queries: one based on the
other. This makes it easier to understand. So perhaps, you do a "group by
and get max" on one and use this in another. If you really want to, though,
you can write it all in one hit and I think this is what you more or less
need:

' *** Start ***
SELECT A.*, B.*

FROM
(Table1 A INNER JOIN
(SELECT id1, id2, Max(somefield) AS MyMax
FROM Table2 GROUP BY id1, id2) AS X
ON A.id2=X.id2 AND A.id1=X.id1)

INNER JOIN

Table2 AS B ON
A.id2=B.id2 AND A.id1=B.id1
' *** End ***

Note that Access may alter this syntax to [my alias select]. square brackets
and dot. This is shown below:

' *** Start ***
SELECT A.*, B.*

FROM
(Table1 A INNER JOIN
[SELECT id1, id2, Max(somefield) AS MyMax
FROM Table2 GROUP BY id1, id2]. AS X
ON A.id2=X.id2 AND A.id1=X.id1)

INNER JOIN

Table2 AS B ON
A.id2=B.id2 AND A.id1=B.id1
' *** End ***
Mar 23 '06 #2
Please don't multi-post!

http://tc2.atspace.com/0012-UsingUse...m#MultiPosting

HTH,
TC (MVP Access)
http://tc2.atspace.com

Mar 23 '06 #3
TC
Please don't multi-post!

http://tc2.atspace.com/0012-UsingUse...m#MultiPosting

HTH,
TC (MVP Access)
http://tc2.atspace.com

Mar 23 '06 #4

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

Similar topics

3
by: sks | last post by:
I have a Product table, a Categories table and a join table that contains product to category mappings (each product can be in many categories) CREATE TABLE categories ( id bigint(20) unsigned...
3
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
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 of Item, and is also a field in LogEvent. Some...
1
by: Eitan M | last post by:
Hello, I want to do select like this : select t1.col_2 from table_1 t1, table_2 t2 where t1.col_1 = t2.col_1 (+) The above is correct syntax for Oracle. What is the correct syntax for...
5
by: rneel | last post by:
I have a query which performs the following Select a2 from table_a left outer join table_b on table_a.a1=table_b.b1 and table_b.b1=999999 The result of set of this is different from ...
9
by: shanevanle | last post by:
I have two tables that are pretty big. I need about 10 rows in the left table and the right table is filtered to 5 rows as well. It seems when I join the tables in the FROM clause, I have to...
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 made a specific kind of B, report the name of that...
2
by: icebox27 | last post by:
Need urgent help! I have 3 tables that are in Left Join ex: select * from tbl_a left outer join tbl_b on tbl_b.f1 = tbl_a.f1 and tbl_b.f2 = tbl_a.f2 left outer join tbl_c on...
3
by: pbassutti | last post by:
Hello, I'm trying to link two tables... one for Employees and the other for Timecards I need to get a list of employees that do not have timecards on an SPECIFIC DATE I tried the follonwing
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.