Solved

LEFT JOIN twice ...

Posted on 2004-04-18
4
456 Views
Last Modified: 2013-12-25
Hello,
Please excuse my poor english. Here is my problem :

Database name = "MainDB"
The main table, named "Main", is made of 3 fields : "Product" , "InStock" and "Missing"

Product  InStock  Missing
--------------------------------------
A            2         4
B            7         2
...

A secondary table named "Translation" is made of 2 fields : "Value" and "Text"

Value  English
---------------------
1        one
2        two
3        three
...

I want the following result on the screen, i.e. translating values to other ones thanks to the "Translation" table. Please note that it is only a sample, I have not only to translate such easy terms !!!

Product  InStock  Missing
--------------------------------------
A            two           four
B            seven        two
...

Here is what I have written :
Dim Ds as Recordset
Set Ds = MainDB.OpenRecordset("SELECT Main.Product, Translation.Text AS A, Translation.Text AS B FROM Main LEFT JOIN (Main LEFT JOIN Translation ON Main.InStock = Translation.Value) ON Main.Missing = Translation.Value) WHERE Product ...", 4)

But is doesn't work ...

Thank you for your help !
Philippe.
0
Comment
Question by:MSelect
  • 2
4 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 10852507
Try this:

SELECT id, Product ,
(Select top 1 English From Translation Where Translation.Value = Main.InStock) As InStock ,
(Select top 1 English From Translation Where Translation.Value = Main.Missing) As Missing
From Main

Hope this helps
0
 
LVL 9

Accepted Solution

by:
p_sie earned 50 total points
ID: 10852593
Try

SELECT translation_1.English as Missing, translation.English as InStock, main.Product
FROM (main LEFT JOIN [translation] ON main.InSock = translation.Value) LEFT JOIN [translation] AS translation_1 ON main.Missing = translation_1.Value
WHERE main.Product="Pro"            <--- Fill in the product you want

This is much faster then using SELECT TOp 1's multiple times, especially if there are many records
0
 

Author Comment

by:MSelect
ID: 10852685
Thank you very much and your remark was really true : using "SELECT Top" was VERY VERY slow, even to get only 3 or 4 records ... I had even thought that my computer had crashed :-)
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10852777
Your welcome!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question