It sounds to me you should run two seperate searches, one for new data, one for old data.
If you have seperate tables with seperate data from seperate timestamps. You can't use a JOIN if there are no overlapping fields.
Here's a PDO snippet you can use for safer queries:
$dbHost = 'databaseHost';
$dbName = 'databaseName';
$dbUser = 'databaseUsername';
$dbPass = 'databasePassword';
/**
* Connect to your database.
*/
try
{
$dsn = 'mysql:dbname=%s;host=%s';
$conn = new PDO(vsprintf($dsn, [$dbName, $dbHost]), $dbUser, $dbPass);
} catch (PDOException $e)
{
/**
* Catch any exceptions in case your connection should fail.
*/
echo 'Failed to connect: '.$e->getMessage();
die();
}
/**
* Build your queries.
*/
$firstQuery = 'SELECT
t1.`BSTKATNR`,
t1.`BSTLIEFBST`,
t1.`BSTARTBES1`,
t1.`BSTANF`,
t1.`BSTSTLIO`,
t1.`BSTLIEFMIN`,
t1.`BSTMIND`,
t1.`BSTARTMASS`,
t1.`BSTKUMST`,
t1.`BSTKUMVK`,
t1.`BSTKUMER`
FROM `table1` AS t1 WHERE
( t1.`BSTLIEFBST` LIKE :BSTLIEFBST ) OR
( t1.`BSTKATNR` LIKE :BSTKATNR ) OR
( t1.`BSTLIEFTXT` LIKE :BSTLIEFTXT ) OR
( t1.`BSTARTBES1` LIKE :BSTARTBES1);'
;
$secondQuery = 'SELECT
t2.`BSTKUMSTVJ`,
t2.`BSTKUMVKVJ`,
t2.`BSTKUMERVJ`
FROM `vorjahr` AS t2 WHERE
( t2.`BSTKUMSTVJ` LIKE :BSTKUMSTVJ) OR
( t2.`BSTKUMVKVJ` LIKE :BSTKUMVKVJ) OR
( t2.`BSTKUMERVJ` LIKE :BSTKUMERVJ);'
;
/**
* Prepare your statements
*/
$stmtOne = $conn->prepare($firstQuery);
$stmtTwo = $conn->prepare($secondQuery);
/**
* Bind your query to all values.
*/
$stmtOne->bindValue(':BSTLIEFBST', '%'.$query.'%', PDO::PARAM_STR);
$stmtOne->bindValue(':BSTKATNR', '%'.$query.'%', PDO::PARAM_STR);
$stmtOne->bindValue(':BSTLIEFTXT', '%'.$query.'%', PDO::PARAM_STR);
$stmtOne->bindValue(':BSTARTBES1', '%'.$query.'%', PDO::PARAM_STR);
$stmtTwo->bindValue(':BSTKUMSTVJ', '%'.$query.'%', PDO::PARAM_STR);
$stmtTwo->bindValue(':BSTKUMVKVJ', '%'.$query.'%', PDO::PARAM_STR);
$stmtTwo->bindValue(':BSTKUMERVJ', '%'.$query.'%', PDO::PARAM_STR);
/**
* Execute the statement
*/
$stmtOne->execute();
$stmtTwo->execute();
/**
* Return your resultset
*/
$resultset1 = $stmtOne->fetchAll();
$resultset2 = $stmtTwo->fetchAll();
Just create two of these and combine your results!