MySQL Forums :: Newbie :: select max date in Inner Join


Advanced Search

select max date in Inner Join
Posted by: the devilz ()
Date: June 29, 2010 05:53AM

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

Options: ReplyQuote


Subject Written By Posted
select max date in Inner Join the devilz 06/29/2010 05:53AM
Re: select max date in Inner Join laptop alias 06/29/2010 06:00AM
Re: select max date in Inner Join the devilz 06/29/2010 06:11AM
Re: select max date in Inner Join laptop alias 06/29/2010 06:46AM
Re: select max date in Inner Join Guelphdad Lake 06/29/2010 05:40PM
Re: select max date in Inner Join the devilz 06/29/2010 07:05AM
Re: select max date in Inner Join laptop alias 06/29/2010 08:02AM


Sorry, you can't reply to this topic. It has been closed.

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.