
mysqlのorder by fieldで指定順にソートする
postgresを長くやっていて、mysqlを初めて触ったときに一番感動したこと
in句で指定している順番で値を取得できるの!?ということでした。
select * from item_mst where item_code where item_code in ('003','001','002')
postgresの場合、簡単にはできなかったのですが、mysqlだと簡単にできました。
order by field を使用することで実現。
select * from item_mst where item_code where item_code in ('003','001','002') order by field(item_code, '003', '001', '002');