mysql选择查询,尝试选择多个值,但查询显示1个值

时间:2017-11-08 11:53:39

标签: mysql wordpress select join

我有WYSPRESS的MYSQL数据库,它有很多表,并尝试进行选择查询以获取请求的数据。

表是:

site_locaion:

siteID(PRIMARY KEY)
locationName
lat
long

雇员:

employeeID(PRIMARY KEY)
employeeName

inspection_info:

inspectionID(PRIMARY KEY)
inspectionDate
employeeID

inspection_site:

inspectionID(PRIMARY KEY)

siteID(PRIMARY KEY)

我正在尝试获取 employeeName 有多个值的以下字段。

SQL qyery

$sql = $wpdb->prepare("select 
       l.locationName
       , n.inspectionDate
       , e.employeeName
  from army_site_location l
  LEFT  
  JOIN inspection_site s
    on l.siteID = s.siteID
  LEFT
    JOIN inspection_info n
    on n.inspectionID = s.inspectionID
    LEFT
  JOIN employeeName e
    on n.employeeID=e.employeeID
     where 
    l.locationName = %s
    AND 
    e.employeeID = %d
    AND 
    n.inspectionID = %d
   ",$site_name,$soldier_name, $inspection_date);

 $query_submit =$wpdb->get_results($sql, OBJECT);

结果必须 2名员工在同一日期和相同位置,但系统只需获取 1名员工

enter image description here

0 个答案:

没有答案