cari

Rumah  >  Soal Jawab  >  teks badan

MySQL 一个left join 查询疑问

c_mart_order_info 表执行

mysql> SELECT order_id,order_sn FROM  `c_mart_order_info` WHERE  `order_sn` =  '16030515100000196809';
+----------+----------------------+
| order_id | order_sn             |
+----------+----------------------+
|       27 | 16030515100000196809 |
+----------+----------------------+
1 row in set (0.00 sec)

c_order_pay 执行

mysql> select order_sn from c_order_pay where order_sn=16030515100000196809;
+----------------------+
| order_sn             |
+----------------------+
| 16030515100000196809 |
+----------------------+
1 row in set (0.00 sec)

两个表 left join 后

mysql> select a.order_sn as a_sn,c.order_sn as c_sn from c_mart_order_info as a left join c_order_pay as c on a.order_sn=c.order_sn where a.order_id=27;
+----------------------+------+
| a_sn                 | c_sn |
+----------------------+------+
| 16030515100000196809 | NULL |
+----------------------+------+
1 row in set (0.00 sec)

两个表都有相同的 order_sn 用left join 查询,为什么只得到一个表的信息,哪里出错了?

------更---------
感谢 woderwang 提醒,我的mysql 版本是5.1,col类型不一样造成,但是某些更新版本的mysql,却没有这个问题,

ringa_leeringa_lee2785 hari yang lalu643

membalas semua(2)saya akan balas

  • 怪我咯

    怪我咯2017-04-17 13:55:44

    column 类型不一样吧,mysql应该会有强制转换,用int处理下再join试试

    balas
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:55:44

    去掉where a.order_id=27。
    你就会发现了。

    balas
    0
  • Batalbalas