Home >Backend Development >PHP Tutorial >mysql 独一查询

mysql 独一查询

WBOY
WBOYOriginal
2016-06-13 11:51:38967browse

mysql 唯一查询
需要查询两列数据中中包含$user的唯一值
例如 $user=猪
有以下数据,表明为sixin
id  shuozhe  tingzhe
1     猪             狗
2    狗              猪
3     牛             马
4     猪              牛

需要查询结果为2,4,(去除和猪无关和重复的)
但是我的查询语句会查询出1,2,4,求解,怎么才能只查询出2,4
查询语句如下

<br /><br />$str="select distinct shuozhe,tingzhe from sixin where (shuozhe='$user' or tingzhe='$user') order by  id desc  " ; //查詢字串<br />


------解决方案--------------------
建议还是把两个字段的所有为 猪 的都取出来 在php判断吧 你这查询要判断交叉式相等了 mysql不好处理

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn