Solved

LEFT JOIN twice ...

Posted on 2004-04-18
4
447 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 49

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now