Solved

LEFT JOIN twice ...

Posted on 2004-04-18
4
455 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 50

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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