如何 select * 从 SQL 中的多个表中 "self-joining"?

How to select * from multiple tables in SQL when "self-joining"?

此查询试图获取有关公司及其母公司的信息:

select c.*, p.*
from companies c, companies p
where c.parent_id = p.id and c.name ilike '%google%'

但这似乎 return 仅来自母公司(后者指定)的数据,并且缺少 c.*

可能是因为这是一个自连接,所以第二个覆盖了第一个?

我正在通过 Sequal 使用它 gem。

您观察到的不是 Postgres 对此查询所做的。它 returns table companies 的所有列两次,每个实例一次,有效地复制列名,这对于一些期望唯一列名的客户来说可能是个问题。

db<>fiddle here