Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- getting the last result
- James Scott
May 26, 2006, 4:11 pm
rate this thread
I have following table:
product| ordered_by | date
n1 | A | 2006-01-01
n1 | A | 2006-02-01
n1 | D | 2006-03-01
n1 | B | 2006-05-01
n2 | B | 2006-01-01
n2 | C | 2006-04-01
As a result I only want one set per product with the latest "ordered_by".
In this example:
n1, B and
So far I solved it within the executing program but I was wondering if there
is an efficient query to do the same.
Re: getting the last result
FROM tablename t1
LEFT OUTER JOIN tablename t2 ON t1.product = t2.product AND t1.`date` <
WHERE t2.`date` IS NULL
In other words, "show me the row where there is no other row with the
same product and a greater date."
- » How can I return a row when the condition is not met ?
- — Previous thread in » MySQL Database Forum
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum