mysql - MySQL inner join changes column value
问题描述
I found something really confusing recently about inner join:
select records.id,
records.amount,
records.payment_amount,
orders.id as or_id
from `records`
**`inner`** `join order_from_site orders on records.id = orders.`record_id`
will somehow set the payment_amount
value to 0.0.
If however, I change the inner
join to left
join, the value is correctly preserved. Not sure if this is the expected behavior or a bug?
I'm using MySQL 8.0.
解决方案
Your question does not provide any data from the two tables so it will be hard to determine the answer to your question without the data.
That said, an inner join requires matched data from both sides to be present in order to display a row. A left join requires the table from the left to be present and only optionally on the right.
推荐阅读
- scala - 在 VScode 中设置 Scala(metals) 时出现问题
- angular - 是否可以使 Angular ReactiveForm ValidatorFn 设置错误几秒钟?
- javascript - 如何修复 React-Redux 中的“第一次访问渲染数据不可访问,但在第二次访问后可访问以进行渲染”错误
- python - 使用 Sheetfu 读取列
- python-3.x - 从列表中仅提取一个元素并将其作为另一个名称写入 csv
- python-3.x - 手动订购多索引级别
- r - 与值序列不同的矩阵暗名
- python - 从 ModelIndex 扩展 QTreeView 项目
- r - 将非 NA 值堆叠到每列的顶部
- sql-server - 使用 JDBC 从表中选择前 N 行的通用方法