title: running a query selecting data from one table and one of two possible other tables depending on data in the first table
body: <p>I'm updating a site at the moment which can potentially run a ridiculous amount of queries!</p>
  
  <p>In simple form, there are 3 tables;</p>
  
  <p><strong>Updates</strong>
  UpdateID
  Files_FileID
  Pages_PageID
  UpdateDate</p>
  
  <p><strong>Pages</strong>
  PageID
  PageTitle</p>
  
  <p><strong>Files</strong>
  FileID
  FileTitle</p>
  
  <p>Files_FileID in the Updates table links to FileID in the Files table
  Pages_PageID in the Updates table links to PageID in the Pages table</p>
  
  <p>At present the code does a select query on the Updates table, then loops through those results running another query for each result on either the Pages table if the Pages_PageID has a value, or on the Files table if the Files_FileID has a value. Now this might have been alright ( if poor practice ) when the site was originally done about 15 years ago, but i'm just about to add nearly 2000 new files that will be listed in the updates table!</p>
  
  <p>I'd like to change it ( if possible ) to run one query. Can this be done?</p>
  
  <p>I can see i could split it into two queries, one for the Pages and one for the Files, but then i'd have two results both based on the UpdateDate and i couldn't display them in the correct order.</p>