sql - 查询不同表的数据

标签 sql postgresql

我在我的 postgres 数据库上使用这样的查询:

SELECT TableA.id FROM TableA , TableB WHERE TableA.id = 100;

每个 TableA.id 都是唯一的(它是一个自动增量),我得到了不止 1 个结果。我在这里遗漏了什么吗?

最佳答案

你需要一个连接:

SELECT TableA.ID from TableA
INNER JOIN TableB 
ON TableB.TableAID = TableA.ID 
WHERE TableA.ID = 100

关于sql - 查询不同表的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/298972/

相关文章:

mysql - 实现mysql交集

postgresql - 使用 go 的 sqlx 在 postgres 表中插入记录并自动生成 ID

postgresql - 在 Postgres 中的特定模式上创建序列时出错

ruby-on-rails - psql 无法连接

PostgreSQL 无法从服务器 : Software caused connection abort (0x00002745/10053) 接收数据

sql - Snowflake 中 COPY INTO 命令中的正则表达式

mysql - 错误代码 : 1054. 'sdate' 中的未知列 'where clause'

php - 快速生成随机 MySQL 行并多次运行相同的 sql 查询

sql - Postgres - 选择 CASE when & order by the same column probme

php - SQL/PHP 从关注您的人中选择您不关注的关注者