title: Saving a SQL query and retrieving data from last query result
body: <p>I'm designing a database and a Java application to the following:<br>
  1. Allow user to query the database via an API.<br>
  2. Allow a user to save a query and identify the query via a 'query-id'. User can then pass-in 'query-id' on next call to API, which will execute the query associated with id but it will only retrieve data from the last time the specific query was requested.<br>
      - Along with this, I would also need to save the query-id information for each UserID. </p>
  
  <p>Information regarding the Database<br>
  The database of choice is PostgreSQL and the information to be requested by user will be stored in various tables. </p>
  
  <p><strong>My question:</strong> Any suggestions/advice/tips on how to go about implementing requirement 
  No. 2?<br>
  Is there an existing design pattern, sql queries, built-in db function on how to save a query and fetch information from multiple tables from the last returned results. </p>
  
  <p>Note:<br>
  My initial thoughts so far is to store the last row(each row in all the tables will have a primary key) read from each table into a data structure and then save this data structure for each saved query and use it when retrieving data again.  </p>
  
  <p>For storing the user and query-id information, I was thinking of creating a separate table to store the UserName, UserUUID, SavedQuery, LastInfoRetrieved.   </p>
  
  <p>Thanks.</p>