I want to execute a simple join on two tables after connecting two columns with ids on one of these tables.
First step:
SELECT cars.hhid & cars.vmid
FROM cars
Now I want to compare this result with another table (table2).
The new result should be every row in table1 (cars) that match with id in table2.
What’s wrong?
My code:
SELECT Cars.*
FROM (SELECT Cars.hhid & Cars.vmid AS zid
FROM cars) x
JOIN table2 ON table2.id = x.zid;
From what you’ve said in the question, I don’t see why you need a subquery at all.
Try this:
(tested with
doubleas data type for all three fields)You don’t need the subquery because you can put your “connected columns” directly into the
JOINclause (of course you can put them into theSELECTclause as well if you need them there).However, as soon as you concatenate the columns, Access seems to treat them as a
string, so you can’t join them directly on thedoublecolumn intable2.That’s why you need to convert the column from table2 to a string with
CStr().