缺少数据的拉结果LEFT JOIN

时间:2019-02-15 12:41:06

标签: mysql select mysqli left-join

如何在查询中与product_id匹配 atm查询仅提取缺少的结果,但每个产品都有自己的记录,需要与此记录匹配

此查询正常,但与product_id不匹配

$query = $this->db->query("SELECT oc_ekstri_frontend.*,
                              oc_ekstri_image.id as img_id,
                              oc_ekstri_image.name
                              FROM oc_ekstri_image
LEFT JOIN oc_ekstri_frontend ON (oc_ekstri_frontend.id = oc_ekstri_image.frontend_id)
LEFT JOIN oc_ekstri_frontend_view ON (oc_ekstri_frontend_view.ekstri_id = oc_ekstri_image.id)
                              WHERE oc_ekstri_frontend.subcat_id = '" . $id . "'
                             AND oc_ekstri_frontend_view.ekstri_id IS NULL");

我将如何匹配当前的product_id? 我尝试将类似的内容添加到查询中,但是工作结果为空

AND oc_ekstri_frontend_view.product_id = '" . $product_id . "'

1 个答案:

答案 0 :(得分:1)

没有看到您的数据或预期的输出,很难给出确切的答案。一种可能的解决方案可能是将您的新限制从string filePath = @"C:\Temp\ExcelTable.xlsx"; Excel.Application excelApp = new Excel.Application(); Excel.Workbook excel_wbk = excelApp.Workbooks.Open(filePath); // This work if there is a shape in Worksheet 1: string altTextShape = excel_wbk.Worksheets[1].Shapes[1].AlternativeText // Code to get excel table alt text? // excel_wbk.Worksheets[1].Tables[1].AlternativeText // or excel_wbk.Worksheets[1].Table[1].AlternativeText doesn't exist excelApp.Quit(); 子句移到WHERE子句:

ON

在以上查询中,我使用SELECT f.*, i.id AS img_id, i.name FROM oc_ekstri_image i LEFT JOIN oc_ekstri_frontend f ON f.id = i.frontend_id LEFT JOIN oc_ekstri_frontend_view v ON v.ekstri_id = i.id AND v.product_id = ? WHERE f.subcat_id = ? AND v.ekstri_id IS NULL; 占位符来建议您使用准备好的语句,而不是在参数中进行串联。如果您不知道PHP中准备好的语句是什么,则应该read about them