如何查询两个 SQL 表并过滤该数据

How to query two SQL tables and filter that data

我正在尝试从这样的两个表中收集数据

SELECT table1.NAME, table2.NAME
FROM table1, table2
WHERE table1.NAME = table2.NAME

然后我希望能够使用新的 SQL 语句查询输出数据,有没有办法做到这一点?

当然,您可以使用 CTE:

with cte as
(SELECT table1.NAME, table2.NAME
FROM table1, table2
WHERE table1.NAME = table2.NAME)
select * from cte --here goes your statement

请注意,您应该使用现代的显式连接语法,而不是您正在使用的旧语法:

with cte as
(SELECT table1.NAME, table2.NAME
FROM table1 inner join table2
on table1.NAME = table2.NAME)
select * from cte --here goes your statement