In my Ms Access, I want to insert data from two different table, so i write the sql like this:
SELECT B.*, C.* INTO Table2 FROM Table1 AS A
RIGHT JOIN ABC AS B ON A.HKID=B.HKID
RIGHT JOIN DEF AS C ON A.HKID=C.HKID
WHERE A.HKID Is Null and b.organization not like '*xxx*' and b.adj = 1 and c.[Status] = 'Suspend';"
but it had error msg when running the sql, it said syntax error.
Can I write the sql like this ?
When you have more than one
JOIN, Access’ db engine requires the use of parentheses.Notice I used …
instead of the way you had it …
I had to make that change because Access complained “join not supported” when I tried
ON A.HKID=C.HKIDIf that is not satisfactory, you will need to start over; I think I would tackle this one with the tables in the opposite order and useLEFT JOIN.Also, the table you create (
Table2) will include fields namedB_HKIDandC_HKID, which come fromB.HKIDandC.HKID. You will see the same pattern with any other field names those 2 tables have in common. If that is unacceptable you can list the fields individually and assign aliases where needed.If you have Access installed, you should build this query in the query designer because it will ensure you set up the joins properly to keep the db engine happy.
If you don’t have Access installed, and you are running this query from an ADO connection, change the wild card character in the
Likestring pattern from*to%.