我可以在sql查询中两次使用where子句吗?

时间:2012-01-26 09:48:12

标签: mysql sql

是否可以像这样编写查询?

SELECT a FROM Action a WHERE a.name = "name" WHERE a.namesafe = "namesafe"

8 个答案:

答案 0 :(得分:4)

您的SQL有一些错误

  1. 您正在选择表别名而不是列。SELECT a FROM Action a。可能你错过了.*
  2. 使用双引号"代替单'
  3. 可能是你要找的是这个,

    SELECT a.* FROM Action a WHERE a.name = 'name' AND a.namesafe = 'namesafe'
    

    但是,您可以使用两个 WHERE 。但这会很棘手。

    SELECT 
        T.* 
    FROM 
        (
            SELECT 
                a.* 
            FROM 
                Action a 
            WHERE 
                a.name = 'name'
        ) AS T 
    WHERE 
        T.namesafe = 'namesafe'
    

答案 1 :(得分:3)

不会抛出错误,但是如果你想使用两个搜索条件,你可以使用它。 SELECT a FROM Action a WHERE a.name = "name" and a.namesafe = "namesafe"

答案 2 :(得分:1)

如果您希望它们都使用AND

SELECT a FROM Action a WHERE a.name = "name" AND a.namesafe = "namesafe"

如果您想使用OR

SELECT a FROM Action a WHERE a.name = "name" OR a.namesafe = "namesafe"

答案 3 :(得分:0)

你必须这样写:

SELECT a FROM Action a WHERE a.name = "name" AND a.namesafe = "namesafe"

答案 4 :(得分:0)

为什么不使用AND

SELECT a FROM Action a WHERE a.name = "name" AND a.namesafe = "namesafe"

答案 5 :(得分:0)

你的意思是AND:

SELECT a FROM Action a WHERE a.name = "name" AND a.namesafe = "namesafe"

答案 6 :(得分:0)

使用AND运算符,您可以加入以下两个条件:

SELECT a.*
FROM Action a 
WHERE a.name = 'name' AND 
      a.namesafe = 'namesafe'

答案 7 :(得分:0)

使用AND运算符

SELECT a FROM Action a WHERE a.name =“name”AND a.namesafe =“namesafe

http://www.w3schools.com/sql/sql_and_or.asp