 <pre><code>select Data.* from Data inner join Page on (Data.PageID=Page.PageID) where Data.PageID=1 order by if(Page.OrderByMethod='Most Recent Data First', now()-DataDate, if(Page.OrderByMethod='Most Recent Data Last', DataDate-now(), DataName) ); </code></pre>