简体   繁体   English

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

[英]How to query two SQL tables and filter that data

I'm trying to gather data from two tables like this我正在尝试从这样的两个表中收集数据

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

then i want to be able to query that output data with a new SQL statement is there a way of doing that?然后我希望能够使用新的 SQL 语句查询 output 数据,有没有办法做到这一点?

Sure, you can use a CTE:当然,您可以使用 CTE:

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

Please note that you should be using the modern explicit join syntax instead of the old one you're using:请注意,您应该使用现代显式连接语法而不是您正在使用的旧语法:

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

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

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