简体   繁体   English

如何在另一张桌子上离开笛卡尔积?

[英]How to left join a Cartesian product on another table?

Using Access 2010. Suppose I have three tables: dogs , cats , and catChases . 使用Access 2010中假设我有三个表: dogscats ,和catChases My goal is to create a query that will tell me, for each dog and each cat, whether or not that dog has chased that cat. 我的目标是创建一个查询,会告诉我,每个狗和猫每一个,那条狗是否已追赶那只猫。

I thought I'd have to use a Cartesian product of dogs and cats , because I want the status for all possible combinations, and then left join catChases , as follows: 我以为我必须使用dogscats的笛卡尔积,因为我想要所有可能组合的状态,然后按如下所示加入加入catChases

select
dog,cat,chase
from
dogs,cats
left join
catChases
on
dogs.dog=catChases.dog

but that just gives me an error message: Syntax error in JOIN operation. 但只是给了我一个错误信息: Syntax error in JOIN operation.

So how do I left join another table to a Cartesian product? 那么,如何将另一个表联接到笛卡尔积上呢?

Try this: 尝试这个:

select x.dog, x.cat,cs.chase 
from 
     (select dog
            ,cat  
     from dogs, cats) x
left join catChases cs on cs.dog=x.dog and x.cat=cs.cat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM