1

I have a question about SQL in parallel queries. For example, suppose that I have this query:

INSERT INTO tblExample (num) VALUES (1), (2)

And this query:

INSERT INTO tblExample (num) VALUES (3)

The final table should looked like this:

num
---
1
2
3

But I wonder if there is an option that those two queries will run in parallel and the final table will be looked like this:

num
---
1
3
2

Someone know the answer?

Thanks in advance!

4

2 回答 2

1

您的表格“看起来”如何取决于您要求它的方式(在SELECT声明中)。如果没有ORDER BY子句,表的顺序是未定义的:

ORDER BY 是对结果集中的行进行排序的唯一方法。如果没有此子句,关系数据库系统可能会以任何顺序返回行。如果需要排序,则必须在应用程序发送的 SELECT 语句中提供 ORDER BY。

例如:

SELECT num FROM tblExample ORDER BY num ASC

1

2

3

SELECT num FROM tblExample ORDER BY num DESC

3

2

1

如果要手动对列进行排序,可以添加一个新列并对其进行排序:

+-----+-------+
| num | order |
+-----+-------+
| 1   | 1     |
| 2   | 3     |
| 3   | 2     |
+-----+-------+

SELECT num FROM tblExample ORDER BY order ASC

1

3

2

于 2012-09-20T22:51:43.410 回答
1

sql中没有顺序。您可以通过添加ORDER BY子句对查询进行排序

SELECT * FROM tblExample ORDER BY num

或者您可以在表中添加一个时间戳列并按此排序。

于 2012-09-20T22:53:22.677 回答