根据两个条件从单列中选择记录

时间:2015-07-30 09:05:56

标签: sql where-clause between

我可能很简单,但我需要解决方案。

我的表中有列Id(1到10),我想要ID在2到4和6到10之间的行,如何检索这些行?任何有用的东西。

2 个答案:

答案 0 :(得分:3)

SELECT * FROM myTable
WHERE ID BETWEEN 2 and 4
OR ID BETWEEN 6 and 10

SQL Fiddle

答案 1 :(得分:1)

SELECT * FROM myTable
WHERE (ID >= 2 and ID <= 4)
OR (ID >= 6 and ID <= 10);