I'm still struggling with this problem (my previous post was about that, and since I've changed the table parameters, I've got another problem):
(Some columns have changed, so it's a different problem/question, since I only have the id as field to get the last insert)
table products:
id name
1 TV
2 RADIO
3 COMPUTER
table sales (product_id is a FK which refers to products):
id_sales feedback product_id
4 GOOD 2
5 GOOD 3
6 NICE 3
The query I'm using:
SELECT products.name, sl.feed
FROM products LEFT JOIN (
SELECT product_id, max(id_sales), feedback AS feed FROM sales GROUP BY product_id) sl
ON products.id = sl.product_id
The result is:
name feed
TV NULL
RADIO GOOD
COMPUTER GOOD
It worked for TV and Radio, but in column Computer, I must show the LAST feedback, which you can see it's 'NICE', not 'GOOD'! Using SQL function MAX(id_sales) somehow is not the solution I thought it was. What am I missing here?