MYSQL + PHP:可以将一个表的结果与数组提供的数据结合起来吗?

Scenario: We have a table where we store our data but also we got some data from an external API. It is possible, to append this external data to our query results so to be able to apply WHERE and ORDER BY conditon. Example:

$a = array(array('RegDate' => '02-10-2018',
                 'JobTitle' => 'Web Designer'
           ),
           array('RegDate' => '03-10-2018',
                 'JobTitle' => 'Account Manager'
           ),
           array('RegDate' => '01-10-2018',
                 'JobTitle' => 'Web Designer'
           ),
           ...
     );


$SQL = SELECT RegDate, JobTitle, CandidateName UNION ALL SELECT $a[]['RegDate'] ,$a[]['JobTitle'] WHERE JobTitle LIKE '%Account%' ORDER BY RegDate DESC

You would probably, deleguate your logic to php instead of MySQL here. Retrieve data from Database then append external data to it:

  • 1 - execute query, get data from DB.
  • 2 - Append external data to data previously returned by database
  • 3 - Sort resulting array