I would like to compare two columns in the same table. I want to be able to return all rows where the two columns have the same value.
我想比较同一个表中的两列。我希望能够返回两列具有相同值的所有行。
I am looking for something like SELECT * FROM FOO WHERE C1 = C4
.
我正在寻找像SELECT * FROM FOO WHERE C1 = C4这样的东西。
Therefore in the example below I would return only the first row:
因此,在下面的示例中,我将只返回第一行:
C1 || C2 || C3 || C4
--------------------------
1 || a || b || 1
2 || a || b || 4
3 || b || d || 2
4 || b || d || 2
If it matters, I am using SQLite
(more specifically WebSQL
).
如果重要,我使用SQLite(更具体地说是WebSQL)。
1 个解决方案
#1
11
SELECT * FROM FOO WHERE C1 = C4
should work. Does it not?
SELECT * FROM FOO WHERE C1 = C4应该有效。不是吗?
If not, are they the same data type and length? You may need to convert.
如果没有,它们的数据类型和长度是否相同?您可能需要转换。
I don't know about WebSql, but I've seen some db systems that refuse to match if one is a varchar(5) and the other is a varchar(10) even though they hold the same value. In those systems you have to use something like
我不知道WebSql,但是我看到一些db系统拒绝匹配,如果一个是varchar(5)而另一个是varchar(10),即使它们保持相同的值。在那些系统中你必须使用类似的东西
Convert(varchar, 10, FieldName)
to get a match.
得到一个匹配。
#1
11
SELECT * FROM FOO WHERE C1 = C4
should work. Does it not?
SELECT * FROM FOO WHERE C1 = C4应该有效。不是吗?
If not, are they the same data type and length? You may need to convert.
如果没有,它们的数据类型和长度是否相同?您可能需要转换。
I don't know about WebSql, but I've seen some db systems that refuse to match if one is a varchar(5) and the other is a varchar(10) even though they hold the same value. In those systems you have to use something like
我不知道WebSql,但是我看到一些db系统拒绝匹配,如果一个是varchar(5)而另一个是varchar(10),即使它们保持相同的值。在那些系统中你必须使用类似的东西
Convert(varchar, 10, FieldName)
to get a match.
得到一个匹配。