简体   繁体   English

选择两列包含值组合的所有行

[英]Select all rows where two columns contain a combination of values

Here's my schema: 这是我的架构:

CREATE TABLE T (A CHAR(1), B CHAR(1));
INSERT INTO T (A, B) VALUES('1', '1');
INSERT INTO T (A, B) VALUES('2', '2');
INSERT INTO T (A, B) VALUES('1', '2');

I wan't to select rows where columns A and B contain a combination of values. 我不会选择A和B列包含值组合的行。 For example, lets say I want to find combinations A=1,B=1, and A=2,B=2, and nothing else. 例如,假设我要查找组合A = 1,B = 1和A = 2,B = 2,而没有其他选择。 If it were a single value, I could use the IN statement, but when I try this: 如果是单个值,则可以使用IN语句,但是当我尝试这样做时:

SELECT * FROM T WHERE A IN ('1', '2') AND B IN ('1', '2')

I get back all three rows. 我退回所有三行。

How can I match a combination of values? 如何匹配值的组合?

Is this what you're looking for using OR with parentheses? 这是您要在括号中使用OR吗?

select * 
from T
where ( A = '1' AND B = '1' ) OR ( A = '2' AND B = '2' )

You can check this query : 您可以检查以下查询:

SELECT * FROM T WHERE (A,B) IN (('1', '1'),('2', '2'));

see given link below 请参阅下面的给定链接

Click here 点击这里

you can use something like below sql 您可以使用类似下面的sql

SELECT * FROM T WHERE (A == B) AND A IN ('1', '2'); 选择*从T位置(A == B)和A IN('1','2');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何选择列组合与值列表匹配的行? - How to select rows where a combination of columns matches a list of values? 从表中选择匹配的行,其中两列之一包含值列表中的任何值 - Select matching rows from a table where either one of two columns contain any value from a list of values 选择两列的值在数组中的行 - Select rows where values of two columns are in array 在SELECT语句中对两列包含不同值的列进行分组 - Grouping in SELECT statement with two columns that contain different values among rows 我如何 select 表中的所有行,其中两列的组合在每一行(SQL Server)上都是不同的? - How can I select all rows from a table where the combination of two columns is distinct on each row (SQL Server)? Select 行,其中两列的组合是唯一的,我们只显示第一列不唯一的行 - Select rows where the combination of two columns is unique and we only display rows where the first column is not unique 如何选择两列组合相同的行 - How to select rows where a combination of 2 columns is the same 选择列表中所有列均具有所有值的所有行 - Select all rows where columns have all values in a list 查找具有两列唯一组合的所有行 - Finding all rows with unique combination of two columns 选择所有行在两列中具有相同值的记录 - Select records where all rows have same value in two columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM