0

As you can see this query is returning 5 rows, but only 3 groups. Is there a way to get this to return 5 groups with an unlimited number of rows in each group?

Many thanks in advance!

The Query:

  $query = 'SELECT t.tenderKey, t.tenderId, t.clientId, t.shortDescription, t.status, t.created
            FROM '.$this->tableTenders.' as t
            INNER JOIN '.$this->tableClients.' as c on t.clientId = c.clientId
            INNER JOIN '.$this->tableUsers.' as cb on t.createdBy = cb.officeId
            LEFT JOIN '.$this->tableUsers.' as lm on t.lastModified = lm.officeId
            ORDER BY t.created DESC LIMIT :offset, :perpg';
  $stmt = $this->conn->prepare($query);
  $stmt->bindValue(':perpg',    5,     PDO::PARAM_INT);
  $stmt->bindValue(':offset',   0,     PDO::PARAM_INT);
  $stmt->execute();
  $data = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);

The Data:

"cfe0e072-f969-71f6-1578-faa0964904dd": [
  {
    "tenderId": "8064",
    "clientId": "1000",
    "shortDescription": "",
    "status": "draft"
  }, {
    "tenderId": "8063",
    "clientId": "1000",
    "shortDescription": "",
    "status": "draft"
  }, {
    "tenderId": "8062",
    "clientId": "1000",
    "shortDescription": "",
    "status": "draft"
  }
],
"642939b3-0de2-9c8a-aeed-bf33856b08eb": [{
  "tenderId": "8061",
  "clientId": "1000",
  "shortDescription": "",
  "status": "draft"
}],
"b01cb9b3-8794-6410-e1b6-014a5c1b0a7f": [{
  "tenderId": "8060",
  "clientId": "1000",
  "shortDescription": "",
  "status": "draft"
}]
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
M_Becker
  • 2,018
  • 2
  • 14
  • 11

1 Answers1

-1

Your query should be more/less like this:

SELECT t.tenderKey, t.tenderId, t.clientId, t.shortDescription, t.status, t.created, cb,officeId, lmx.officeId AS 'LastModified_officeId'
    (SELECT lm.officeId 
     FROM '.$this->tableUsers.' as lm 
     WHERE t.lastModified = lm.officeId LIMIT 1) lmx
FROM '.$this->tableTenders.' as t
JOIN '.$this->tableClients.' as c on t.clientId = c.clientId
JOIN '.$this->tableUsers.' as cb on t.createdBy = cb.officeId
Ged Clack
  • 1
  • 2