search
LoginSignup
0

More than 1 year has passed since last update.

posted at

[MySQL]id一覧をカンマ区切りで取得したい

SQL文を作成する際に、コンマ区切りのidが欲しい時など。

SQL

SELECT
    group_concat(id)
FROM
    order
WHERE
    created_at > '2020-10-01 00:00:00'
;

結果

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| group_concat(id)                                                                                                                                                                                                                                                                                                                                                                                                                       |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 16798554,16798555,16798556,16798557,16798558,16798559,16798560,16798561,16798562,16798563,16798564,16798565,16798566,16798567,16798568,16798569,16798570,16798571,16798572,16798573,16798574,16798575,16798576,16798577,16798578,16798579,16798580,16798581,16798582,16798583,16798584,16798585,16798586,16798587,16798588,16798589,16798590,16798591,16798592,16798593,16798594,16798595,16798596,16798597,16798598,16798599,16798600 |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0