Just a side note - I'd use a different query (it may be invalid but I mean the general idea):
SELECT
MAX(cardid)+1 AS 'id',
t.date,
o.name,
t.amount
FROM `transactions` AS t
INNER JOIN `operations` AS o ON t.operation=o.id
WHERE
operation>=1000 && operation<2000 GROUP BY cardid
ORDER BY date;
SELECT
MAX(cardid)+1 AS 'id',
t.date,
o.name,
t.amount
FROM `transactions` AS t
INNER JOIN `operations` AS o ON t.operation=o.id
WHERE
operation>=1000 && operation<2000 GROUP BY cardid
ORDER BY date;
To copy to clipboard, switch view to plain text mode
MAX is safer than COUNT.
But honestly that's a perfect usecase for triggers - you can have a trigger that will calculate the id itself and modify the query on the fly.
Bookmarks