mb89
05-06-2008, 04:33 AM
Hi,
I don't understand joins etc as well as I should as I have gotten a bit stuck now.
I have a table of items which have been tested multiple times on different test reports. I have to select all of the items to ensure I only get one entry but I then need to sort by the report date to get information about the report from the most recent occurance of the item. Basically its something like this:
SELECT
item.*
FROM item
LEFT JOIN test_report_items ON test_report_items.ID = item.itemID
LEFT JOIN test_report ON test_report.ID = test_report_items.test_reportID
WHERE
item.companyID = '4'
ORDER BY
test_report.date DESC,
item.productID
So the problem with this though is when we do the first left join, there will be multiple matching records to join to but I need the most recent. How can I tell a left join to do this?
Any advice would be appreciated.
I don't understand joins etc as well as I should as I have gotten a bit stuck now.
I have a table of items which have been tested multiple times on different test reports. I have to select all of the items to ensure I only get one entry but I then need to sort by the report date to get information about the report from the most recent occurance of the item. Basically its something like this:
SELECT
item.*
FROM item
LEFT JOIN test_report_items ON test_report_items.ID = item.itemID
LEFT JOIN test_report ON test_report.ID = test_report_items.test_reportID
WHERE
item.companyID = '4'
ORDER BY
test_report.date DESC,
item.productID
So the problem with this though is when we do the first left join, there will be multiple matching records to join to but I need the most recent. How can I tell a left join to do this?
Any advice would be appreciated.