select max date in Inner Join
Hello,
I am using many tables,
1. user table
having information about user along with when he created account
2. user address
having addresses of users. As users have many addresses
3. order table
having information about his order along with the date when he made his order
now for report generation I want to Select the MAX date (last ordered date)
I am using this but i am not getting what i want
SELECT users.*, useraddress.*, MAX( invoice.last_updated )
FROM users
INNER JOIN useraddress ON useraddress.Userid = users.Userid
INNER JOIN invoice ON invoice.userid = users.Userid
WHERE (SELECT MAX( invoice.last_updated ) FROM invoice GROUP BY invoice.userid) >= '2010-6-21'
AND (SELECT MAX( invoice.last_updated ) FROM invoice GROUP BY invoice.userid) <= '2010-6-22'
ORDER BY `users`.`Fname` ASC
I tried this too
SELECT users.userid, users.Fname, users.Sname, users.LastUpdated, useraddress.Address1, useraddress.Address2, useraddress.City, useraddress.Country, useraddress.PostalCode, useraddress.HomeNo, useraddress.MobileNo, MAX( invoice.last_updated )
FROM users
INNER JOIN useraddress ON useraddress.Userid = users.Userid
INNER JOIN (SELECT MAX(last_updated) FROM invoice GROUP BY userid) AS invoice ON invoice.userid = users.Userid
AND TO_DAYS( invoice.last_updated ) >= TO_DAYS( '2010-6-21' )
AND TO_DAYS( invoice.last_updated ) <= TO_DAYS( '2010-6-22' )
GROUP BY users.Fname
ORDER BY `users`.`Fname` ASC
but it gives error:: #1054 - Unknown column 'invoice.last_updated' in 'field list' on line number 2
plz help me
Thank you
Subject
Written By
Posted
select max date in Inner Join
June 29, 2010 05:53AM
Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.