连接导致的数据错误

时间:2017-12-09 04:34:45

标签: mysql sql join

如何删除我在运行的几个连接后得到的虚幻数据。

我的整个查询是:

SELECT 
 distinct vortex_dbo.vw_public_material_location.material_name

 ,vw_public_request_material_location_mir.material_request_id
 ,vw_public_request_material_location_mir.parttype_name
 ,operation_code
 ,vw_public_request_material_location_mir.result_name
 ,vw_public_request_material_location_mir.qdf_number
      , requestor
      ,[vortex_hvc].[vortex_dbo].[material_request].created_by
      ,[vortex_hvc].[vortex_dbo].[material_request].created_datetime as time1
      ,[vortex_hvc].[vortex_dbo].[material_request].distribution_list 
      ,[vortex_hvc].[vortex_dbo].[material_request].recipient_name
      , DATEPART(WW,[vortex_hvc].[vortex_dbo].[material_request].created_datetime) as WW
      ,vw_public_request_material_location_mir.product_code_name
      ,task_name
      ,vw_public_request_material_location_mir.full_location_name

  FROM [vortex_hvc].[vortex_dbo].[vw_public_request_material_location_mir]


         left join request on vw_public_request_material_location_mir.material_request_id = request.request_key
        left join vortex_dbo.material_request on vw_public_request_material_location_mir.material_request_id = vortex_dbo.material_request.material_request_id
        left join vortex_dbo.vw_public_material_location on vw_public_request_material_location_mir.last_result_id = vortex_dbo.vw_public_material_location.last_result_id
          left join vortex_dbo.vw_public_material_history on  vw_public_request_material_location_mir.material_request_id like (substring(vw_public_material_history.comments,12,6)) 


  where (vw_public_request_material_location_mir.qdf_number not like 'null' and vw_public_request_material_location_mir.qdf_number  not like '')

  and vw_public_request_material_location_mir.product_code_name like 'LAKE%'

  and vw_public_request_material_location_mir.task_id not like 'null'

  and (vw_public_request_material_location_mir.result_name like 'bin 100' or  vw_public_request_material_location_mir.result_name like 'bin 01'
   or  vw_public_request_material_location_mir.result_name like 'bin 02' or vw_public_request_material_location_mir.result_name like 'pass')
 and (requestor like 'BUGANIM, RINAT' and employee_name like 'BUGANIM, RINAT')




  and  ( DateDiff(DD,[vortex_hvc].[vortex_dbo].[material_request].created_datetime, getdate()) < 180)



 and (concat('',substring(vortex_dbo.vw_public_material_location.comments,12,6)) like vw_public_request_material_location_mir.material_request_id


  or vortex_dbo.vw_public_material_location.comments like 'Changed by Matrix Transaction Handler' or vortex_dbo.vw_public_material_location.comments like 'Unit Ownership:%')

  and (unit_number = vortex_dbo.vw_public_material_location.material_name or unit_number is null)

  and vortex_dbo.vw_public_material_location.material_name like 'D7QM748200403'

 order by vortex_dbo.vw_public_material_location.material_name desc

我得到的结果是: 两行只有第二行包含真实数据。

material_name   material_request_id parttype_name   operation_code  result_name qdf_number  requestor   created_by  time1   WW  product_code_name   task_name   full_location_name
D7QM748200403   332160  H6 4GXDCV K Y   7295    BIN 01  Q1T5    BUGANIM, RINAT  SMS_Interface   2017-12-03 20:27:30.327 49  CANNON LAKE Y 2+2   PPV-M   SAMPLE: QDF INVENTORY
D7QM748200403   332176  H6 4GXDCV K Y   7295    BIN 01  Q1T5    BUGANIM, RINAT  SMS_Interface   2017-12-03 21:02:33.247 49  CANNON LAKE Y 2+2   PPV-M   SAMPLE: QDF INVENTORY

我只能检索真实数据?我有更多这样的情况。 谢谢!

0 个答案:

没有答案