?
Solved

LEFT JOIN twice ...

Posted on 2004-04-18
4
Medium Priority
?
463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

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 200 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses

765 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