在mySQL查询

时间:2016-11-19 21:39:45

标签: mysql sql

我试图通过浏览W3's tutorials来学习使用mySQL。我正在阅读有关SQL BETWEEN运算符以及它如何允许您选择范围内的值的内容。我正在关注tutorial example

SELECT * FROM Products
WHERE ProductName BETWEEN 'C' AND 'M';

并认为如果你也可以按升序排序按ProductName排序会很酷。我试过了:

SELECT * FROM Products
WHERE ProductName BETWEEN 'C' AND 'M' AND OrderBY ASC;

SELECT * FROM Products
WHERE ProductName BETWEEN 'C' AND 'M';
AND OrderBY ASC;

以及

SELECT * FROM Products
WHERE ProductName BETWEEN 'C' AND 'M', OrderBY ASC;

每个人都会出错:

'Syntax error (missing operator) in query expression'

但是我在使用多个参数时不确定正确的语法。更一般地说,我想知道SQL查询是否可以有多个参数。即选择此表并根据参数1和参数2进行排序,或者如果您需要为每个操作创建单独的查询。

1 个答案:

答案 0 :(得分:3)

这是正确的语法:

SELECT *
FROM Products
WHERE ProductName BETWEEN 'C' AND 'M'  -- no comma/semicolon after [WHERE] clause
ORDER BY ProductName ASC;              -- ORDER BY colName..