0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Posted at

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)
0
0
0

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
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?