SQL高级过滤

时间:2013-12-03 13:13:53

标签: sql sql-server-2008 tsql

我正在尝试使用where子句过滤数据,但我需要过滤两种类型的行。 例如:

processID ProcessName processorName
-----------------------------------
461        a                ABC
116        a                XYZ
755        c                ABC
031        b                EFG
333        b                KLM

假设我们这个表包含三个颜色,我想要检索ProcessNameab的行,但不仅仅是a processorName } ABCb processorName KLM

2 个答案:

答案 0 :(得分:3)

这应该这样做:

SELECT processID, ProcessName, processorName
FROM table
WHERE (ProcessName = 'a' AND processorName = 'ABC')
   OR (ProcessName = 'b' AND processorName = 'KLM')

答案 1 :(得分:0)

试试这个:

select * from table a where processNmae='a' and processorname ='ABC'

    union

    select * from table a where processNmae='b' and processorname='KLM'

see fiddle demo here