 <p>Use a <code>case</code>. Generally you can do</p> <pre><code>SELECT records.some_id FROM forms LEFT OUTER JOIN records ON forms.form_id = records.form_id ORDER BY case when records.some_id is not null then 1 else 2 end, records.some_id </code></pre> <p>and specifically in MySQL you can also do</p> <pre><code>SELECT records.some_id FROM forms LEFT OUTER JOIN records ON forms.form_id = records.form_id ORDER BY records.some_id is not null, records.some_id </code></pre>