Php 如何组合这些mysql查询
问题1 问题2Php 如何组合这些mysql查询,php,mysql,Php,Mysql,问题1 问题2 $query = "SELECT stock_issue.*,stock_item.item_name FROM stock_issue,stock_item WHERE stock_issue.idate>=$from AND stock_issue.idate<=$to AND stock_issue.item_id=stock_item.ID ORDER BY stock_issue.idate DESC"; 请帮帮我…你可以用
$query = "SELECT stock_issue.*,stock_item.item_name
FROM stock_issue,stock_item
WHERE stock_issue.idate>=$from
AND stock_issue.idate<=$to
AND stock_issue.item_id=stock_item.ID
ORDER BY stock_issue.idate DESC";
请帮帮我…你可以用工会把它合并起来
$query = "SELECT stock_purchase.*,stock_item.item_name
FROM stock_purchase,stock_item
WHERE stock_purchase.pdate>=$from
AND stock_purchase.pdate<=$to
AND stock_purchase.itemid=stock_item.ID
ORDER BY stock_purchase.pdate DESC";
用UNION试试这个
(SELECT stock_issue.*,stock_item.item_name FROM stock_issue,stock_item where stock_issue.idate>=$from and stock_issue.idate<=$to and stock_issue.item_id=stock_item.ID) UNION (SELECT stock_purchase.*,stock_item.item_name FROM stock_purchase,stock_item where stock_purchase.pdate>=$from and stock_purchase.pdate<=$to and stock_purchase.itemid=stock_item.ID)
请尝试使用此代码
$sql="SELECT stock_issue.*,stock_item.item_name FROM stock_issue,stock_item where stock_issue.idate>=$from and stock_issue.idate<=$to and stock_issue.item_id=stock_item.ID ORDER BY stock_issue.idate DESC
UNION
SELECT stock_purchase.*,stock_item.item_name FROM stock_purchase,stock_item where stock_purchase.pdate>=$from and stock_purchase.pdate<=$to and stock_purchase.itemid=stock_item.ID ORDER BY stock_purchase.pdate DESC";
谢谢你的回复…我收到了你的回复…我收到了
SELECT stock_issue.*,stock_item.item_name
FROM stock_issue,stock_item
WHERE stock_issue.idate>='$from'
AND stock_issue.idate<='$to'
AND stock_issue.item_id=stock_item.ID
ORDER BY stock_issue.idate DESC
UNION
SELECT stock_purchase.*,stock_item.item_name
FROM stock_purchase,stock_item
WHERE stock_purchase.pdate>='$from'
AND stock_purchase.pdate<='$to'
AND stock_purchase.itemid=stock_item.ID
ORDER BY stock_purchase.pdate DESC
$sql=$query1.'UNION'.$query2;