<code>SELECT * FROM `subject` WHERE Subject_id IN (1602509) OR 1=1 LIMIT 5 比如数据库里面有一条记录 Subject_id =1602509,我的结果集想查询出5条记录,并且包含 Subject_id =1602509这一条记录,SQL该如何写呢?? 如果没有Subject_id =1602509这条记录,那么就用其他数据补齐5条记录</code>
<code>SELECT * FROM `subject` WHERE Subject_id IN (1602509) OR 1=1 LIMIT 5 比如数据库里面有一条记录 Subject_id =1602509,我的结果集想查询出5条记录,并且包含 Subject_id =1602509这一条记录,SQL该如何写呢?? 如果没有Subject_id =1602509这条记录,那么就用其他数据补齐5条记录</code>
<code>SELECT * FROM `subject` WHERE Subject_id IN (1602509) UNION SELECT * FROM `subject` WHERE Subject_id NOT IN (1602509) LIMIT 5</code>
실제로 이것도 효과가 있습니다
비즈니스 계층에서 구현하는 것이 가장 좋습니다