Try this: CREATE TEMPORARY TABLE max_entry SELECT NoPeople, Max(Date_entry) AS Date_entry FROM table;
SELECT NoPeople FROM table NATURAL JOIN max_entry WHERE Departure IS NULL; > Hi all :) > > I have 1 relation A. > > Structure of A: > NoPeople > Date_entry > Date_departure > > and key is (NoPeople + Date_entry) > > exemple of records: > > NoPeople Entry Departure > P1 E1 D1 > P1 E2 D2 > P1 E3 NULL > > P2 E1 NULL > > P3 E1 D1 > > P4 E1 NULL > P4 E2 NULL > P4 E3 D2 > > E3>E2>E1 and D2>D1. P1,P2,P3 and P4 are different persons. > > I would like to query all the people whose date_entry is their MAX date > entry AND that have their date departure to NULL. In this exemple, P1 > and P2 are ok. P4 isn't ok because max(Date_entry) is E3 and > Date_departure - when Date_entry is E3 - isn't NULL. > > I tried some queries with 'group by' but i can't make it working. > Any hint "sql masters" :) > > fab > > > > > > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] > -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]