データベースにこのような名前がある場合
A
C
D
B
キーワードを使用するgroup by
と、なぜsqliteがこのようなデータを与えるのか
A
B
C
D
なぜデータを順番に返すのですか?? 順序を維持する必要はありません。を使用して元の形式を維持する方法はありますかgroup by
To expand on TokenMacGuy's answer:
A real database can have hundreds of tables, each with thousands of rows, each having a variable number of rows. The database software (MySQL, SQL Server, etc.) manages where and how each of these items are stored in memory. Let's say that there is a table whose rows are stored in three different places in the hard drive. When you do a SELECT
statement on that table, and you don't have ORDER BY
, the database software grabs the appropriate rows and shoves them into the output.
SQLite is different - the file is generally smaller, generally local. When you do a SELECT
statement on a table in SQLite, the information is likely stored in the same place. To quote the sqlite language specification,
"If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined." Notice that the language specification does not guarantee that the rows won't be in order.
Long story short, the GROUP BY
only changes which rows show, not what order those rows are returned in. Try creating multiple tables, and inserting to them in different orders, at different times, then running your SELECT
again. It will likely not be in order this time.
データベース内の行は特定の順序ではなく、特定の順序で返されることもありません。
つまりorder by
、クエリで句を指定しない限りです。