mysql - 特定列的 MySQL 内部联接
问题描述
我有 2 张桌子:
表product
:
product_id | 产品名称 | 价格 | 添加了_on | modified_on |
---|---|---|---|---|
1 | 电话 | 100 | 2021-09-25 | 2021-09-25 |
表product_image
:
ID | product_id | product_image1 | 添加了_on | modified_on |
---|---|---|---|---|
1 | 1 | 手机图片.jpg | 2021-09-27 | 2021-09-27 |
我正在尝试在具有内部联接的页面中显示产品图像表,但问题是我的 added_on 和 modified_on 具有相同的名称,我想从 table product
product_id
、product_name
和price
table product_image
all 中进行选择。
到目前为止,我已经使用了这个查询:
SELECT * FROM `product_image`
INNER JOIN `product` ON product_image.product_id = product.product_id
ORDER BY `id` DESC
产品图片展示:
解决方案
不要选择所有列。使用从任何表中选择您需要的列tableName.columnName
SELECT
product.product_id,
product.product_name,
product.price ,
product_image.added_on,
product_image.modified_on
FROM product_image
inner join product
on product_image.product_id = product.product_id
ORDER BY id DESC
推荐阅读
- excel - Excel公式创建两个日期之间的年份范围
- java - AnyLogic - 修改代理变量
- javascript - 使用 ml5 的身体分割过滤器
- sql - 分区依据 - 对所有值求和,不包括最大值
- javascript - 在手动页面刷新之前,不会应用使用 Ajax 成功功能更新属性值
- angular - 如何在方法之间更改选项值的值
- c - C内联汇编无序?
- python - 是否有与 Geopandas.sjoin 等效的 C++,因为它在 Python 上运行速度非常慢?
- pdf-parsing - 如何使用类TCPDF解析器解析pdf文件
- java - Mapstruct 会自动为请求添加参数吗?