Select … where … OR

后端 未结 7 972
误落风尘
误落风尘 2021-02-05 09:09

Is there a way to select data where any one of multiple conditions occur on the same field?

Example: I would typically write a statement such as:

select          


        
相关标签:
7条回答
  • 2021-02-05 09:16

    while in is a shortcut for or and I wasn't sure how I could combine in with and, I did it this way

     SELECT * FROM table
     WHERE column1='x' AND (column2='y' OR column2='z');
    
    0 讨论(0)
  • 2021-02-05 09:20
    select * from TABLE where field IN (1,2,3)
    

    You can also conveniently combine this with a subquery that only returns one field:

        select * from TABLE where field IN (SELECT boom FROM anotherTable)
    
    0 讨论(0)
  • 2021-02-05 09:28

    OR:

    SELECT foo FROM bar WHERE baz BETWEEN 1 AND 3
    
    0 讨论(0)
  • 2021-02-05 09:29
    WHERE field IN (1, 2, 3)
    
    0 讨论(0)
  • 2021-02-05 09:32

    You can still use in for

    select *
    from table
    where field  = '1' or field = '2' or field = '3'
    

    its just

    select * from table where field in ('1','2','3')
    
    0 讨论(0)
  • 2021-02-05 09:35

    select * from TABLE where field in (1, 2, 3)

    0 讨论(0)
提交回复
热议问题