 <pre><code>select * from (select id,subject_id FROM table group by subject_id)tempalias where subject_id=1 select * from (select id,subject_id FROM table group by subject_id)tempalias where subject_id=2 </code></pre>