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
double
as data type for all three fields)You don't need the subquery because you can put your "connected columns" directly into the
JOIN
clause (of course you can put them into theSELECT
clause 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 thedouble
column intable2
.That's why you need to convert the column from table2 to a string with
CStr()
.Try
MS Access like the join type to be specified.
* Answer for TSQL, prior to learning it was MS-Access *
SQL has no
double
data type, so you'll need to use float.To use the concatenation operator
+
the values will need to be converted to a string usingCAST
orCONVERT
Data:
Query:
* Attempt at MS-Access *
Does this work any better, to me it looks like your table references are slightly wring