Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:17:13+00:00 2026-06-15T19:17:13+00:00

A small disaster happened to me on my database postgresql ver. 8.4. Help me

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:17:14+00:00Added an answer on June 15, 2026 at 7:17 pm

    Is this your home assignment for database class?

    You first have to select the latest and earliest rows from History for every visitor:

    select uniqid, max(whenseenlast) from history group by uniqid
    

    and

    select uniqid, min(whenseenlast) from history group by uniqid
    

    then select the records that match them for your history table, something like this:

    select frst.uniqid, whenseenfirst, whereseenfirst, whenseenlast, whereseenlast
    from
    (select h.uniqid, mn.mnseen as whenseenfirst, h.whereseenlast as whereseenfirst
        from history h
        join (select uniqid, min(whenseenlast) as mnseen from history group by uniqid) mn
        on mn.mnseen = h.whenseenlast and mn.uniqid = h.uniqid) frst,
    (select h.uniqid, mx.mxseen as whenseenlast, h.whereseenlast as whereseenlast
        from history h
        join (select uniqid, max(whenseenlast) as mxseen from history group by uniqid) mx
        on mx.mxseen = h.whenseenlast and mx.uniqid = h.uniqid) lst
    where frst.uniqid = lst.uniqid
    

    You can verify it on SQLFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A small - little question. I have seen many application having buttons like following.
have small problem, and would very much appreciate help :) I should convert byte
small questions about Restrictions. i have query like this : Where A in(1,6) and
Small preamble. I was good java developer on 1.4 jdk. After it I have
We (small team) currently have our Visual Studio projects on a network drive (no
Small script, being used to send one of two .pdf files to the user
I have an application used by pretty tech-savey people and they want small island
small questions about Restrictions.or and Restrictions.and If I do something like this: ... criterion
one small issue in my movieplayer..![movieplayer shows like this] 1 : https://i.stack.imgur.com/WujxB.png but i
Small introduction: I've tried to develop my project with sql database, entity framework, linq.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.