MYSQL LEFT JOIN返回空

时间:2019-06-11 10:39:04

标签: mysql sql

我有三个表,

表1和表2

需要比较:component_name与产品以及component_version与版本 如果这些值相同,则从table2中获取相应的cvid

表2和表3

现在相对于表2-cvid值等于表3-cvid值 (实际值应该相等)完全匹配的字符串

我尝试过使用表

表1:upload_bom

CREATE TABLE IF NOT EXISTS `upload_bom` (
  `component_name` varchar(100) NOT NULL,
  `component_version` varchar(20) NOT NULL
) 

表2:cpe_cse

CREATE TABLE IF NOT EXISTS `cpe_cse` (
  `id` varchar(20) NOT NULL,
  `cpe` varchar(20) NOT NULL,
  `argument` varchar(20) NOT NULL,
  `vendor` varchar(100) NOT NULL,
  `product` varchar(100) NOT NULL,
  `version` varchar(20) NOT NULL,
  `subversion` varchar(20) NOT NULL,
  `platform` varchar(100) NOT NULL,
  `cvid` varchar(20) NOT NULL
)

表3:cses

CREATE TABLE IF NOT EXISTS `cses` (
  `cvid` varchar(20) NOT NULL,
  `cvss` varchar(20) NOT NULL,
  `description` varchar(5000) NOT NULL
)

因此,我尝试了一个代码

但是当我尝试加入cpe_csv.cvid = cses.cvid时,我得到了空值,但相同的查询在sqlite中有效,而在MySQL中却不可用

下面是我尝试过的查询

SELECT DISTINCT upload_bom.component_name, upload_bom.component_version, cpe_cse.cvid, cses.cvid, cses.description
FROM upload_bom
LEFT JOIN cpe_cse on upload_bom.component_name = cpe_cse.product AND upload_bom.component_version = cpe_cse.version
LEFT JOIN cses on cpe_cse.cvid = cses.cvid

我必须显示

Select upload.bom_Component_name, upload_bom.component_version, cpe_cse.cvid, cses.cvid, cses.description
       component_name , component_version , cpe_cse.cvid, cses.cvid, cses.description
       "freebsd","1.1","cv1999-0001","cv1999-0001", "this is an software"

在连接两个表的两列同时获取空值的同时,我想过来并连接表

0 个答案:

没有答案