{"id":3960,"date":"2023-05-02T12:00:56","date_gmt":"2023-05-02T03:00:56","guid":{"rendered":"https:\/\/www.bold.ne.jp\/engineer-club\/?p=3960"},"modified":"2025-11-19T11:02:30","modified_gmt":"2025-11-19T02:02:30","slug":"sql-order-by","status":"publish","type":"post","link":"https:\/\/www.bold.ne.jp\/engineer-club\/sql-order-by","title":{"rendered":"SQL\u306eORDER BY\u53e5\u3068\u306f\uff1f\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u308bORDER BY\u53e5\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"<p><strong>SQL\u3067\u62bd\u51fa\u3057\u305f\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u308b\uff08\u30bd\u30fc\u30c8\u3092\u884c\u3046\uff09\u5834\u5408\u306fORDER BY\u53e5\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/strong><\/p>\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001ORDER BY\u53e5\u3092\u4f7f\u3063\u3066<span style=\"text-decoration: underline;\">\u30bd\u30fc\u30c8\u3092\u884c\u3046\u65b9\u6cd5<\/span>\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002\u307e\u305f\u3001\u4ee5\u4e0b\u306e\u30e6\u30fc\u30b6\u30fc\uff08<span>user<\/span>\uff09\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<table style=\"height: 144px; width: 100%; border-collapse: collapse;\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">ID<\/td>\n<td style=\"width: 25%; height: 24px;\">name<\/td>\n<td style=\"width: 25%; height: 24px;\">age<\/td>\n<td style=\"width: 25%; height: 24px;\">group_id<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">1<\/td>\n<td style=\"width: 25%; height: 24px;\">User1<\/td>\n<td style=\"width: 25%; height: 24px;\">30<\/td>\n<td style=\"width: 25%; height: 24px;\">103<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">2<\/td>\n<td style=\"width: 25%; height: 24px;\">User2<\/td>\n<td style=\"width: 25%; height: 24px;\">25<\/td>\n<td style=\"width: 25%; height: 24px;\">103<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">3<\/td>\n<td style=\"width: 25%; height: 24px;\">User3<\/td>\n<td style=\"width: 25%; height: 24px;\">27<\/td>\n<td style=\"width: 25%; height: 24px;\">101<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">4<\/td>\n<td style=\"width: 25%; height: 24px;\">User4<\/td>\n<td style=\"width: 25%; height: 24px;\">23<\/td>\n<td style=\"width: 25%; height: 24px;\">101<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">5<\/td>\n<td style=\"width: 25%; height: 24px;\">User5<\/td>\n<td style=\"width: 25%; height: 24px;\">35<\/td>\n<td style=\"width: 25%; height: 24px;\">102<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#i\">\uff11\uff0e\u6607\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b<\/a><\/li><li><a href=\"#i-2\">\uff12\uff0e\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b<\/a><\/li><li><a href=\"#i-3\">\uff13\uff0e\u8907\u6570\u306e\u30bd\u30fc\u30c8\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u4e26\u3079\u66ff\u3048\u308b<\/a><\/li><li><a href=\"#i-4\">\uff14\uff0e\u307e\u3068\u3081<\/a><\/li><\/ul><\/div>\n<h2><span id=\"i\">\uff11\uff0e\u6607\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b<\/span><\/h2>\n<p>\u305d\u308c\u3067\u306f\u307e\u305a\u3001\u5bfe\u8c61\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u6607\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3067\u3059\u3002\u4f8b\u3068\u3057\u3066\u3001\u30e6\u30fc\u30b6\u30fc\uff08<span>user<\/span>\uff09\u30c6\u30fc\u30d6\u30eb\u3092\u7528\u3044\u3066\u6607\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong><span class=\"f-marker-p\">\u4f8b\uff09\u30e6\u30fc\u30b6\u30fc\uff08user\uff09\u30c6\u30fc\u30d6\u30eb\u3092\u3001\u5e74\u9f62\uff08age\uff09\u306e\u6607\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u5834\u5408<\/span><\/strong><\/p>\n<pre class=\"prettyprint lang:default decode:true\">SELECT * FROM user ORDER BY age ASC;<\/pre>\n<p><strong><span class=\"f-marker-w\">\u25bd\u5b9f\u884c\u7d50\u679c<\/span><\/strong><\/p>\n<table style=\"height: 144px; width: 100%; border-collapse: collapse;\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">ID<\/td>\n<td style=\"width: 25%; height: 24px;\">name<\/td>\n<td style=\"width: 25%; height: 24px;\">age<\/td>\n<td style=\"width: 25%; height: 24px;\">group_id<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">4<\/td>\n<td style=\"width: 25%; height: 24px;\">User4<\/td>\n<td style=\"width: 25%; height: 24px;\">23<\/td>\n<td style=\"width: 25%; height: 24px;\">101<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">2<\/td>\n<td style=\"width: 25%; height: 24px;\">User2<\/td>\n<td style=\"width: 25%; height: 24px;\">25<\/td>\n<td style=\"width: 25%; height: 24px;\">103<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">3<\/td>\n<td style=\"width: 25%; height: 24px;\">User3<\/td>\n<td style=\"width: 25%; height: 24px;\">27<\/td>\n<td style=\"width: 25%; height: 24px;\">101<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">1<\/td>\n<td style=\"width: 25%; height: 24px;\">User1<\/td>\n<td style=\"width: 25%; height: 24px;\">30<\/td>\n<td style=\"width: 25%; height: 24px;\">103<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">5<\/td>\n<td style=\"width: 25%; height: 24px;\">User5<\/td>\n<td style=\"width: 25%; height: 24px;\">35<\/td>\n<td style=\"width: 25%; height: 24px;\">102<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3001\u5bfe\u8c61\u306e\u9805\u76ee\u306e\u6607\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002\u6b21\u306b\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2><span id=\"i-2\">\uff12\uff0e\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b<\/span><\/h2>\n<p>\u305d\u308c\u3067\u306f\u7d9a\u3044\u3066\u306f\u3001\u5bfe\u8c61\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3067\u3059\u3002\u4f8b\u3068\u3057\u3066\u3001\u30e6\u30fc\u30b6\u30fc\uff08<span>user<\/span>\uff09\u30c6\u30fc\u30d6\u30eb\u3092\u7528\u3044\u3066\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong><span class=\"f-marker-p\">\u4f8b\uff09\u30e6\u30fc\u30b6\u30fc\uff08user\uff09\u30c6\u30fc\u30d6\u30eb\u3092\u3001\u5e74\u9f62\uff08age\uff09\u306e\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u5834\u5408<\/span><\/strong><\/p>\n<pre class=\"prettyprint lang:default decode:true\">SELECT * FROM user ORDER BY age DESC;<\/pre>\n<p><strong><span class=\"f-marker-w\">\u25bd\u5b9f\u884c\u7d50\u679c<\/span><\/strong><\/p>\n<table style=\"height: 144px; width: 100%; border-collapse: collapse;\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">ID<\/td>\n<td style=\"width: 25%; height: 24px;\">name<\/td>\n<td style=\"width: 25%; height: 24px;\">age<\/td>\n<td style=\"width: 25%; height: 24px;\">group_id<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">5<\/td>\n<td style=\"width: 25%; height: 24px;\">User5<\/td>\n<td style=\"width: 25%; height: 24px;\">35<\/td>\n<td style=\"width: 25%; height: 24px;\">102<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">1<\/td>\n<td style=\"width: 25%; height: 24px;\">User1<\/td>\n<td style=\"width: 25%; height: 24px;\">30<\/td>\n<td style=\"width: 25%; height: 24px;\">103<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">3<\/td>\n<td style=\"width: 25%; height: 24px;\">User3<\/td>\n<td style=\"width: 25%; height: 24px;\">27<\/td>\n<td style=\"width: 25%; height: 24px;\">101<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">2<\/td>\n<td style=\"width: 25%; height: 24px;\">User2<\/td>\n<td style=\"width: 25%; height: 24px;\">25<\/td>\n<td style=\"width: 25%; height: 24px;\">103<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">4<\/td>\n<td style=\"width: 25%; height: 24px;\">User4<\/td>\n<td style=\"width: 25%; height: 24px;\">23<\/td>\n<td style=\"width: 25%; height: 24px;\">101<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3001\u5bfe\u8c61\u306e\u9805\u76ee\u306e\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002\u6700\u5f8c\u306b\u3001\u8907\u6570\u306e\u30bd\u30fc\u30c8\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u4e26\u3079\u66ff\u3048\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2><span id=\"i-3\">\uff13\uff0e\u8907\u6570\u306e\u30bd\u30fc\u30c8\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u4e26\u3079\u66ff\u3048\u308b<\/span><\/h2>\n<p>\u305d\u308c\u3067\u306f\u3001\u8907\u6570\u306e\u30bd\u30fc\u30c8\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u4e26\u3079\u66ff\u3048\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3067\u3059\u3002ORDER BY\u53e5\u3067\u306f\u3001\u9805\u76ee\u3054\u3068\u306b\u6607\u9806\u3068\u964d\u9806\u3092\u8a2d\u5b9a\u3057\u3066\u4e26\u3079\u66ff\u3048\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002\u4f8b\u3068\u3057\u3066\u3001\u30e6\u30fc\u30b6\u30fc\uff08<span>user<\/span>\uff09\u30c6\u30fc\u30d6\u30eb\u3092\u7528\u3044\u3066\u30b0\u30eb\u30fc\u30d7<span>ID<\/span>\uff08<span>group_id<\/span>\uff09\u3092\u6607\u9806\u306b\u3001\u5e74\u9f62\uff08<span>age<\/span>\uff09\u3092\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong><span class=\"f-marker-p\">\u4f8b\uff09\u30e6\u30fc\u30b6\u30fc\uff08user\uff09\u30c6\u30fc\u30d6\u30eb\u3092\u3001\u30b0\u30eb\u30fc\u30d7ID\uff08group_id\uff09\u306e\u6607\u9806\u3001\u304b\u3064\u3001\u5e74\u9f62\uff08age\uff09\u306e\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u5834\u5408<\/span><\/strong><\/p>\n<pre class=\"prettyprint lang:default decode:true\">SELECT * FROM user ORDER BY group_id ASC, age DESC;<\/pre>\n<p><strong><span class=\"f-marker-w\">\u25bd\u5b9f\u884c\u7d50\u679c<\/span><\/strong><\/p>\n<table style=\"height: 144px; width: 100%; border-collapse: collapse;\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">ID<\/td>\n<td style=\"width: 25%; height: 24px;\">name<\/td>\n<td style=\"width: 25%; height: 24px;\">age<\/td>\n<td style=\"width: 25%; height: 24px;\">group_id<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">3<\/td>\n<td style=\"width: 25%; height: 24px;\">User3<\/td>\n<td style=\"width: 25%; height: 24px;\">27<\/td>\n<td style=\"width: 25%; height: 24px;\">101<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">4<\/td>\n<td style=\"width: 25%; height: 24px;\">User4<\/td>\n<td style=\"width: 25%; height: 24px;\">23<\/td>\n<td style=\"width: 25%; height: 24px;\">101<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">5<\/td>\n<td style=\"width: 25%; height: 24px;\">User5<\/td>\n<td style=\"width: 25%; height: 24px;\">35<\/td>\n<td style=\"width: 25%; height: 24px;\">102<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">1<\/td>\n<td style=\"width: 25%; height: 24px;\">User1<\/td>\n<td style=\"width: 25%; height: 24px;\">30<\/td>\n<td style=\"width: 25%; height: 24px;\">103<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px;\">2<\/td>\n<td style=\"width: 25%; height: 24px;\">User2<\/td>\n<td style=\"width: 25%; height: 24px;\">25<\/td>\n<td style=\"width: 25%; height: 24px;\">103<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3001\u8907\u6570\u306e\u30bd\u30fc\u30c8\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u4e26\u3079\u66ff\u3048\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<h2><span id=\"i-4\">\uff14\uff0e\u307e\u3068\u3081<\/span><\/h2>\n<p>\u4ee5\u4e0a\u3001<span>SQL<\/span>\u306e<span>ORDER BY<\/span>\u53e5\u3067\u30bd\u30fc\u30c8\u3092\u884c\u3046\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u30bd\u30fc\u30c8\u3092\u884c\u3063\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f\u662f\u975e\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL\u3067\u62bd\u51fa\u3057\u305f\u30c7\u30fc\u30bf\u3092\u4e26\u3079\u66ff\u3048\u308b\uff08\u30bd\u30fc\u30c8\u3092\u884c\u3046\uff09\u5834\u5408\u306fORDER BY\u53e5\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002 \u672c\u8a18\u4e8b\u3067\u306f\u3001ORDER BY\u53e5\u3092\u4f7f\u3063\u3066\u30bd\u30fc\u30c8\u3092\u884c\u3046\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002\u307e\u305f\u3001\u4ee5\u4e0b\u306e\u30e6\u30fc\u30b6\u30fc\uff08user\uff09\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002  [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":3963,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/3960"}],"collection":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/comments?post=3960"}],"version-history":[{"count":7,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/3960\/revisions"}],"predecessor-version":[{"id":6124,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/3960\/revisions\/6124"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media\/3963"}],"wp:attachment":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media?parent=3960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/categories?post=3960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}