选择列值相等且不相等的id

时间:2017-10-30 08:53:58

标签: mysql sql

这是一个示例表:

id  |  column1  |  column2 
thr |  0        |  100
pop |  100      |  100
poi |  0        |  100

输出应为

id 
thr
poi

上面的表ID具有不同的列值

另一个输出应该是

id
pop

使用常见列值

2 个答案:

答案 0 :(得分:1)

Different: SELECT id FROM table_name_here WHERE column1 != column2;
Same: SELECT id FROM table_name_here WHERE column1 == column2;

答案 1 :(得分:0)

对条件运算符使用WHERE子句。

用于选择具有相同column1column2值的ID。然后,

<强>查询

select `id` from `your_table_name`
where `column1` = `column2`;

用于选择具有不同column1column2值的ID。然后,

<强>查询

select `id` from `your_table_name`
where `column1` <> `column2`;
相关问题