日期:2014-05-16  浏览次数:20779 次

2个SQL合并查询出结果
第一个是

$query = "SELECT Item_Data,R.Run_ID,R.FLOW_ID FROM flow_run_data D INNER JOIN flow_run R ON R.Run_ID = D.Run_ID
  AND flow_id =58 where D.Item_ID=5 and Item_Data !=''";
得出结果 张三,李四,
第二个是
select D.Item_Data from flow_run_data D Inner join
  (
  SELECT D.RUN_ID, ITEM_DATA
  FROM flow_run_data D
  INNER JOIN flow_run R ON R.Run_ID = D.Run_ID
  AND flow_id =58
  WHERE D.Item_ID =5
  AND item_Data ='$val'
  ) A on D.Run_ID=A.Run_ID where D.Item_ID=21
$val就等于张三,李四 等到结果23,24
这样要查询2次我想一次查询
张三23,李四24

------解决方案--------------------
select D.Item_Data from flow_run_data D Inner join
(
SELECT D.RUN_ID, ITEM_DATA
FROM flow_run_data D
INNER JOIN flow_run R ON R.Run_ID = D.Run_ID
AND flow_id =58
WHERE D.Item_ID =5
AND item_Data in($query的SQL语句)
) A on D.Run_ID=A.Run_ID where D.Item_ID=21
------解决方案--------------------
select D.Item_Data from flow_run_data D Inner join
(
SELECT D.RUN_ID, ITEM_DATA
FROM flow_run_data D
INNER JOIN flow_run R ON R.Run_ID = D.Run_ID
AND flow_id =58
WHERE D.Item_ID =5
AND item_Data =(SELECT Item_Data,R.Run_ID,R.FLOW_ID FROM flow_run_data D INNER JOIN flow_run R ON R.Run_ID = D.Run_ID
AND flow_id =58 where D.Item_ID=5 and Item_Data !=')
) A on D.Run_ID=A.Run_ID where D.Item_ID=21