简体   繁体   English

检查特定行中是否存在值

[英]Check if Value exists in Specific Row

I have this table我有这张桌子

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";

I want to check if VALUE is present in row of USER or not (only I want to check in row which is in front of USER value not other rows or columns) How can I check?我想检查 VALUE 是否存在于 USER 行中(只有我想检查 USER 值前面的行,而不是其他行或列)我该如何检查?

A simple query to do what you need would be;一个简单的查询来做你需要的事情;

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

An SQLfiddle to test with .一个用于测试的 SQLfiddle

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM