Hello, Maybe this query can help you
SELECT p.name, l.name FROM location l INNER JOIN product_move m ON m.source_location = location.id INNER JOIN product p ON m.product_id = p.id WHERE p.id = $product_id AND m.datetime < $given_date ORDER BY datetime DESC LIMIT 1 It will return the name of the product and the location for a given id and date. 2013/2/21 denero team <denerot...@gmail.com> > Hi All, > > I need some help for my problem. > Problem : > I have following tables > 1. Location : > id, name, code > 2. Product > id, name, code, location ( ref to location table) > 2. Product_Move > id, product_id ( ref to product table), source_location (ref to > location table) , destination_location ( ref to location table) , > datetime ( date when move is created) > > now i want to know for given period of dates, where is the product > actually. > > can anyone help me ?? > > Thanks, > > Dhaval > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql >