[英]Select Mysql Query issue to get data from two tables
我有两张桌子。
1. tbl_courier (It has 2 Columns)
cons_no, orignal_awb
0906018 109118084926
0906018 109118085755
0906019 109118086800
etc
2. tbl_awb (it has 4 columns)
id awb_no courier_id active`
35 109118084926 8 y
36 109118085755 8 y
37 109118086800 8 y
38 109118086900 9 y
39 109118086950 9 y
cons_no, orignal_awb courier_id
0906018 109118084926 8
0906018 109118085755 8
0906019 109118086800 9
Select t.cons_no, t.orignal_awb, a.awb_no, a.courier_id
From tbl_courier t
JOIN awb a on t.orignal_awb = a.awb_no
cons_no orignal_awb awb_no courier_id
0906018 109118084926 109118084926 8
可能是您的值包含一些隐藏字符,因为空间尝试修剪连接值
Select t.cons_no, t.orignal_awb, a.awb_no, a.courier_id
From tbl_courier t
INNER JOIN awb a on trim(t.orignal_awb) = trim(a.awb_no)
当我使用这个查询时
选择 t.cons_no, t.orignal_awb, a.awb_no, a.courier_id From tbl_courier t LEFT JOIN awb a on t.orignal_awb = a.awb_no
I get the following Result.
-------------------------------------------------
cons_no orignal_awb awb_no courier_id
0906019 109118344346 NULL NULL
0906019 1319418102705 NULL NULL
0906019 43275512350 NULL NULL
0906019 789525214389 NULL NULL
0906018 109118085755 NULL NULL
0906018 109118084926 109118084926 8
而我想要这样:
cons_no orignal_awb awb_no courier_id
0906019 109118344346 109118344346 15
0906019 1319418102705 1319418102705 15
0906019 43275512350 43275512350 15
0906019 789525214389 789525214389 15
0906018 109118085755 109118085755 8
0906018 109118084926 109118084926 8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.