SQL INNER JOIN返回null结果

时间:2015-05-23 05:33:20

标签: mysql sql codeigniter

我想从两个表中获取数据。因为我使用内部联接加入。第一个表具有我想要的所有细节,第二个表具有比该数据更多的细节。

查询数据后,我得到第二个表值的空数据。

SELECT * FROM 
          facility_costdel as fc 
          LEFT OUTER JOIN 
          basic_facility_del as bf
          on fc.facility_code = bf.facility_code

我的查询有问题吗?

1 个答案:

答案 0 :(得分:0)

你正在尝试的正确..如果有任何匹配的数据,它应该返回行。 然后有三种可能无法返回结果

1. There is no matching facility_code between two tables.
2. If matching facility_code is there then match case can be different..
   (lower case and upper case)
3. Third case is leading or trailing spaces.

我猜您使用的是sql server ..请尝试以下代码

SELECT * FROM 
          facility_costdel as fc 
          JOIN 
          basic_facility_del as bf
          on ltrim(rtrim(fc.facility_code)) = ltrim(rtrim(bf.facility_code))