检查特定行中是否存在值

时间:2015-10-02 16:13:42

标签: php mysql database mysqli

我有这张桌子

Num |  id1  |  id2  |  id3
---------------------------
1   |  abc  |  sjs  |  hss    
2   |  abc  |  sjs  |  hss    
3   |  sjs  |  hss  |  uaj     
4   |  ahs  |  shh  |  ajs    
5   |  dks  |  sns  |  jaj


$user = "3";
$value = "hss";

我想检查USER行中是否存在VALUE(仅我想检查USER值前面的行而不是其他行或列)我该如何检查?

1 个答案:

答案 0 :(得分:1)

执行您需要的简单查询;

SELECT *
FROM mytable
WHERE 'hss' IN (id1, id2, id3)
  AND num <= 3;

An SQLfiddle to test with