title: How to take the max value for every element in SQL
body: <pre><code>CREATE TABLE Department(
      DNumber integer NOT NULL PRIMARY KEY);
  
  CREATE TABLE Patient(
      PID integer NOT NULL PRIMARY KEY,
      P_DNumber integer NOT NULL REFERENCES Department (DNumber)
  );
  
  CREATE TABLE Appointment(
      AppNumber integer NOT NULL PRIMARY KEY,
      AppDate date NOT NULL,
      App_DNumber integer  NOT NULL  REFERENCES Department (DNumber)
  );
  
  CREATE TABLE Attend(
      A_PID integer NOT NULL REFERENCES Patient (PID),
      A_AppNumber integer NOT NULL REFERENCES Appointment(AppNumber)
  );
  </code></pre>
  
  <p>HEllo, I have these tables and I want to find for each PID the last Date he attended an appointment. I tried with joins but nothing worked. I am using Postgres. Does anyone have an idea about it?</p>
  
  <p>Thank you very much</p>