A couple of things in that almost all countries have your previous entries especially now with the finger prints taken at the airport. Some have facial recognition too with your picture being taken at immigration. Some obviously share data too. At immigration level it is rather basic but at higher level they get your information on their own data base. With APIS being implemented they obviously know who is coming before the aircraft lands though the frontline officer would not know that unless there is an alert issued.