1

sales&表中的所有记录器purchase只输入一次。我已经仔细检查过了。但是,我希望以这样的方式组合这两个表,以便两个表都被完全提取。这是我的查询说明,该timestamp列具有 mysqlDATE格式

Select 
    sales.ID as sid,
    sales.saleHatsh,
    sales.timestamp as sdate,
    sales.gatePass as sGP,
    sales.pname as sPN,
    sales.description as sDES,
    sales.balance as sbal, 
    purchase.ID as pid,
    purchase.purchaseHatsh,
    purchase.timestamp as pdate,
    purchase.gatePass as pGP,
    purchase.pname as pPN,
    purchase.description as pDES,
    purchase.balance as pbal 
from sales,purchase 
where sales.timestamp='2013-11-11' OR purchase.timestamp='2013-11-11'

这是我的查询 & sales&purchase表 的结果查询结果 Sales表只有 2 个记录器 在此处输入图像描述

采购表只有4个记录仪 在此处输入图像描述

4

1 回答 1

2

那里发生的事情是您没有以任何方式加入这些表格。所以你从这些表中得到了所有可能的匹配。看看我不认为你想加入的列,但可能你想要一个UNION

SELECT 
  sales.ID AS id,
  sales.saleHatsh AS hatsch,
  sales.TIMESTAMP AS date,
  sales.gatePass AS GatePass,
  sales.pname AS pname,
  sales.description AS Description,
  sales.balance AS balance,
  'SALE' AS transanctionType
FROM sales
WHERE sales.TIMESTAMP = '2013-11-11'
UNION 
SELECT 
  purchase.ID,
  purchase.purchaseHatsh,
  purchase.TIMESTAMP,
  purchase.gatePass,
  purchase.pname,
  purchase.description,
  purchase.balance,
  'PURCHASE'
FROM purchase
WHERE purchase.TIMESTAMP = '2013-11-11'

我添加了一个“transactionType”列供您识别哪些是销售或购买。

于 2013-11-11T17:37:25.500 回答