在子查询上加入 [英] JOIN on Subquery

查看:89
本文介绍了在子查询上加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个表之一上连接具有ID的列后,在两个表上执行简单的联接.

I want to execute a simple join on two tables after connecting two columns with ids on one of these tables.

第一步:

SELECT cars.hhid & cars.vmid
FROM cars

现在,我想将此结果与另一个表(table2)进行比较.

Now I want to compare this result with another table (table2).

新结果应该是表1(汽车)中与表2中的id匹配的每一行.

The new result should be every row in table1 (cars) that match with id in table2.

怎么了?

我的代码:

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.

尝试一下:

select cars.*
from cars 
inner join table2 on cstr(table2.id) = cars.hhid & cars.vmid

(已使用 double 作为所有三个字段的数据类型进行了测试)

您不需要子查询,因为您可以将连接的列"直接放入JOIN子句中(当然,如果需要,也可以将它们放入SELECT子句中).

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 the SELECT clause as well if you need them there).

但是,一旦将列连接起来,Access似乎会将它们视为string,因此您不能直接将它们连接到table2中的double列. 这就是为什么您需要使用CStr()将table2的列转换为字符串的原因.

However, as soon as you concatenate the columns, Access seems to treat them as a string, so you can't join them directly on the double column in table2.
That's why you need to convert the column from table2 to a string with CStr().

这篇关于在子查询上加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆