数据库组错误

时间:2015-05-12 21:05:41

标签: php mysql

我一直在使用Mysql,但这是我第一次遇到这个问题。

问题是我有一个选择查询...

SELECT
    transactions.inventoryid,
    inventoryName,
    inventoryBarcode,
    inventoryControlNumber,
    users.nombre,
    users.apellido,
    transactionid,
    transactionNumber,
    originalQTY,
    updateQTY,
    finalQTY,
    transactionDate,
    transactionState,
    transactions.observaciones
FROM
    transactions
LEFT JOIN 
    inventory ON inventory.inventoryid = transactions.inventoryid
LEFT JOIN 
    users ON transactions.userid = users.userid
GROUP BY
    transactions.transactionNumber
ORDER BY
    transactions.inventoryid

但GROUP BY正在从QUERY中删除2个值。

在这种情况下,当我输出:

foreach($inventory->inventory as $values){
    $transactionid[] = $values['inventoryid'];
}

它返回:

2,3,5

如果我删除了GROUP BY语句,则返回

2,3,4,5,6

这是特殊情况下我需要的输出。

问题是:

这是否有理由发生? 如果我按事务进行分组并且应该影响查询,那么它不会只返回1个值吗?

也许我在考虑这个问题,或者在代码上工作太久,我没有看到我逻辑中的明显缺陷。但是,如果有人可以伸出援助之手,我会很感激。

1 个答案:

答案 0 :(得分:1)

In standard SQL you can only selenium-webdriver/testing colums which are

  • contained in SELECT clause
  • (or) aggregate "colums", like GROUP BY or MAX().

You need to consult the MySQL description of the interpretation they use for columns which are not contained by COUNT() (and which are no aggregated column) MySQL Handling of GROUP BY to find out what happens here.

Do you need more information?