I want to create a query that will select only the last "Something" from a table (in that table we mast have a date column !) (more about this here)
example:
SELECT
t.transaction_id,
t.name,
c.comment,
.
.
.
c.datecreated
FROM
transactions t
JOIN ( SELECT
transaction_id,
MAX(datecreated) as datecreated
FROM
transactioncomments
GROUP BY transaction_id ) m
ON t.transaction_id = m.transaction_id
JOIN transactioncomments c
ON t.transaction_id = c.transaction_id AND
m.datecreated = t.datecreated
example:
SELECT
t.transaction_id,
t.name,
c.comment,
.
.
.
c.datecreated
FROM
transactions t
JOIN ( SELECT
transaction_id,
MAX(datecreated) as datecreated
FROM
transactioncomments
GROUP BY transaction_id ) m
ON t.transaction_id = m.transaction_id
JOIN transactioncomments c
ON t.transaction_id = c.transaction_id AND
m.datecreated = t.datecreated
Comentarii