0

I have a series of 4 tables that I need to loop through and pull information to make a new table in an access database:

SELECT *
  FROM tbl_f
 INNER JOIN( SELECT P, Area
               FROM tbl_l
              UNION ALL
             SELECT P, Area
               FROM tbl_m
              UNION ALL
             SELECT P, Area
               FROM tbl_w) ON tbl_f.P;

My Code includes:

Dim strSQL as string 

strSQL = "SELECT * FROM tbl_f inner JOIN( SELECT P, Area FROM tbl_l UNION ALL SELECT P, Area FROM tbl_m UNION ALL SELECT P, Area FROM tbl_w) ON tbl_f.P;"

I keep getting an error that the JOIN is not supported. I've used joins this way before, but any ideas?

1
  • 2
    You are not joining tbl_f to anything. You need to alias the sub query and join on that. ....SELECT P, Area FROM tbl_w) as q ON tbl_f.P=q.p; Commented Sep 7, 2021 at 13:49

2 Answers 2

3

Your join syntax is not correct. Your updated query should look alike -

SELECT *
  FROM tbl_f
 INNER JOIN( SELECT P, Area
               FROM tbl_l
              UNION ALL
             SELECT P, Area
               FROM tbl_m
              UNION ALL
             SELECT P, Area
               FROM tbl_w) T ON (tbl_f.P = T.P);
Sign up to request clarification or add additional context in comments.

Comments

-1

The bottom line with the "on" is your problem.

Missing an "=" along with whatever you are joining on:

FROM tbl_w) ON tbl_f.P = SOMETHING

Maybe consider an outer join if you want to include nulls for blank rows

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.