mysql 独一查询

WBOY
Release: 2016-06-13 11:51:38
Original
925 people have browsed it

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 />
Copy after login


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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!