A small disaster happened to me on my database postgresql ver. 8.4.
Help me please!
I have to follow my visitors on my webpage in two tables like:
TABLE history
whereseenlast varchar(50) uniqid varchar(13) primary key whenseenlast timestamp bla1 varchar(10) bla2 varchar(10) bla3 varchar(10)
example:
where1.html, **1**, 2000-01-01 00:00:00, somebla1, somebla2, somebla3 where2.html, **1**, 2005-05-05 05:06:07, somebla1, somebla2, somebla3 ... where12345.html, **1**, 2012-11-22 11:22:33, somebla1, somebla2, somebla3
TABLE visitors (uniqid is primary key, each visitor can be found just once in this table)
wherseenfirst varchar(50) whereseenlast varchar(50) whenseenfirst timestamp whenseenlast timestamp uniqid varchar(13) PRIMARY KEY notes varchar (20) xyz varchar(20)
example:
where1.html, where12345.html, 2000-01-01 00:00:00, 2012-11-22 11:22:33, 1, somenote, somexyz
I accidentally deleted the TABLE visitors and I have no backup. But, I am sure it is easy for an expert to rebuild the TABLE visitors from the TABLE history with a query.
(I know I will not be able to restore the notes and xyz COLUMNS from TABLE history but that is not a big deal)
Could you please suggest solution?
Is this your home assignment for database class?
You first have to select the latest and earliest rows from History for every visitor:
and
then select the records that match them for your history table, something like this:
You can verify it on SQLFiddle