Sql 如何在三个表上应用联接?
我有三个表customer、address和city,我想找到每个客户来自的城市。因此,我使用了两个连接,但在执行查询后,我发现没有两个客户拥有相同的城市。根据我的查询,是否有人可以帮助我,我的查询是否确定。 我正在使用Sql 如何在三个表上应用联接?,sql,postgresql,Sql,Postgresql,我有三个表customer、address和city,我想找到每个客户来自的城市。因此,我使用了两个连接,但在执行查询后,我发现没有两个客户拥有相同的城市。根据我的查询,是否有人可以帮助我,我的查询是否确定。 我正在使用pagila数据库 select c.first_name , ct.city from customer c join address a on c.address_id=a.address_id join city ct on a.city_id=ct.city
pagila
数据库
select c.first_name , ct.city
from customer c
join address a on c.address_id=a.address_id
join city ct on a.city_id=ct.city_id
这就是你所期待的吗
select distinct c.first_name , ct.city from customer c
join address a on c.address_id=a.address_id
join city ct on a.city_id=ct.city_id
我删除了不一致的数据库标记。仅使用实际使用的数据库进行标记。示例数据和所需结果也将被删除。@GordonLinoff我正在使用pgAdmin作为我的查询editor@GordonLinoff这是对的。你的问题部分-我发现没有两个客户拥有同一个城市,根据我的查询“根据你的数据可能是真的。如果不查看样本数据和预期结果,我们无法知道。你能提供样本数据和预期结果吗?需要数据,而不是关系