Solved

FULL OUTER JOIN

Posted on 2010-11-16
13
1,074 Views
Last Modified: 2012-05-10
I try to create query inside Excel VBA

Table looks like

Param_1     Param_2   Param_3     Month     Value
 1                  2               3                   1           5
 1                  3               3                   1           6
 1                  3               4                   1           7
 2                  2               3                   2           5
 2                  3               3                   2           6
 1                  3               4                   2           7  

Query looks like

SELECT TBL1.Param_1 as Param1_1, TBL1.Param_2 as Param2_1, TBL1.Param_3 as Param3_1, TBL1.Month as Month_1, TBL2.Month as Month_2, TBL1.Value as Value_1, TBL2.Value as Value_2 FROM Table1 as TBL1 FULL OUTER JOIN Table1 as TBL2 ON  TBL1.Param_1 =  TBL2.Param_1 AND TBL1.Param_2=TBL2.Param_2 AND TBL1.Param_3=TBL2.Param_3 WHERE TBL1.Month = 1 AND TBL2.Month = 2

Method "Open" of Object "Recordset" failed

When I use LEFT or INNER join I get some results but I need FULL OUTER JOIN
I already tried to create copy of table and join them - same result

Please advise
0
Comment
Question by:C_sharp_beaver
  • 6
  • 3
  • 2
  • +2
13 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 300 total points
ID: 34149179
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 50 total points
ID: 34149261
you can use a Left, Right Joins and Union the queries to get the results like what the Full Outer joins will return

something like this

SELECT *
FROM   employee
       LEFT JOIN department
          ON employee.DepartmentID = department.DepartmentID
UNION
SELECT *
FROM   employee
       RIGHT JOIN department
          ON employee.DepartmentID = department.DepartmentID;



0
 

Author Comment

by:C_sharp_beaver
ID: 34149649
testing...
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:C_sharp_beaver
ID: 34149751
UNION does not help

as you can see I have more complex ON restrictions. By some reason does not help. Does not collaps but amount of records like INNER JOIN
0
 

Author Comment

by:C_sharp_beaver
ID: 34149774
I agree that FULL OUTER JOIN cannot be created. But I need way around
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 300 total points
ID: 34149894
This still uses the UNION idea, but there is one extra join:

http://www.databasejournal.com/features/msaccess/article.php/3516561/Implementing-the-Equivalent-of-a-FULL-OUTER-JOIN-in-Microsoft-Access.htm

I've looked at a dozen posts, and they all point to the UNION work around.  Not saying there is not another way, just not seeing it yet.

mx
0
 

Author Comment

by:C_sharp_beaver
ID: 34150007
This databasejournal thing is good. Additional problem due to complex query I'm running out AMOUNT OF LINES inside VBA query

Testing...
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 34150093
C_sharp_beaver,

It would help if you would post the SQL that you are testing.  (Also, please put it in the Code section and attach it to the response. ;-)
0
 

Author Comment

by:C_sharp_beaver
ID: 34150125
Advice about code is perfect but cannot follow due to security restrictions
0
 
LVL 22

Assisted Solution

by:8080_Diver
8080_Diver earned 150 total points
ID: 34150139
C_sharp_beaver,

Was your test SQL something like the attached?
SELECT TBL1.Param_1           AS Param1_1
     , TBL1.Param_2           AS Param2_1
     , TBL1.Param_3           AS Param3_1
     , TBL1.Month             AS Month_1
     , TBL2.Month             AS Month_2
     , TBL1.Value             AS Value_1
     , TBL2.Value             AS Value_2
FROM   Table1                 AS TBL1
LEFT OUTER JOIN Table1 AS TBL2
       ON      TBL1.Param_1   =  TBL2.Param_1
              AND TBL1.Param_2=TBL2.Param_2
              AND TBL1.Param_3=TBL2.Param_3
WHERE  TBL1.Month             = 1
       AND TBL2.Month         = 2
UNION
SELECT TBL1.Param_1           AS Param1_1
     , TBL1.Param_2           AS Param2_1
     , TBL1.Param_3           AS Param3_1
     , TBL1.Month             AS Month_1
     , TBL2.Month             AS Month_2
     , TBL1.Value             AS Value_1
     , TBL2.Value             AS Value_2
FROM   Table1                 AS TBL2
LEFT OUTER JOIN Table1 AS TBL1
       ON      TBL1.Param_1   =  TBL2.Param_1
              AND TBL1.Param_2=TBL2.Param_2
              AND TBL1.Param_3=TBL2.Param_3
WHERE  TBL1.Month             = 1
       AND TBL2.Month         = 2
AND TBL1.Param1 IS NULL

Open in new window

0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 34150169
C-sharp_beaver,

Advice about code is perfect but cannot follow due to security restrictions

You already posted some code . . . if that code is what your code is like, then posting a similarly obfuscated clip of SQL indicated your test SQL would probably suffice.  Please note that, since we have no idea what you are writing and testing, we have no idea whether your test SQL is anywhere near correct. ;-)
0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 34153121
Hi,

Use only Outer Join
0
 

Author Closing Comment

by:C_sharp_beaver
ID: 34156244
We trying to work around limitation of specific product.

As soon as application progress let's say to SQL Server our life will become easy

Life is perfect in perfect world (c)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

828 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