php - 根据各自的日期时间字段从两个不同的表中获取记录 - mysql

标签 php mysql

我试图通过比较两个不同的表 ordersorder_returns 各自的日期时间字段来获取数据。

下面是架构

ORDERS table
    order_id | date_1 | amount
       1      10-10-18    50
       2      11-10-18    100
       3      13-10-18    200

订单返回表

order_return_id | order_id | date_2
     1              3       13-10-18

输出应该是

order_id  | order_return_id  | amount | date_1  | date_2
  1               NULL           50      10-10-18   NULL
  2               NULL           100     11-10-18   NULL
  3               1              200     13-10-18   13-10-18

我知道这可以通过执行左连接来实现,但我想以这种方式显示结果。下面是链接

the order_returns data should appear when the date_1 matches date_2

https://ibb.co/kfX18p

红色部分应该出现在箭头所指的位置

最佳答案

使用左连接

select order_id , order_return_id, amount,date_1 ,date_2
from ORDERS left join Orderreturns
on date_1=date_2

关于php - 根据各自的日期时间字段从两个不同的表中获取记录 - mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52759858/

相关文章:

php - MySQL SELECT 或 SUBSELECT 与 PHP

php - 通过 php 在 Maria db 上以 swe7 格式插入数据

java - SQL 查询未在 Java 应用程序中执行

php - MYSQL 与 PHP 的并发

php - 强制http/https : How to detect https and which status header to send when redirecting?

php - 使用 PHP 连接到 Google Analytics API

php - 查询将 'Array' 而不是值插入数据库

php - Mysql通过函数INSERTing数据

php - php中的搜索框与mysql

php - 从 MySQL 数据库中选择的数据不显示