Home > Backend Development > PHP Tutorial > MSQL取不重复数据,生手求教

MSQL取不重复数据,生手求教

WBOY
Release: 2016-06-13 12:06:53
Original
818 people have browsed it

MSQL取不重复数据,新手求教

本帖最后由 u011546401 于 2014-09-25 04:46:25 编辑 php           MYSQL的数据库
有 A,B两个表,
A表除ID外有AA和BB两个字段
id       BB       AA
1         1          1
2         2          1
3         3          1
4         1          2
5         4          2
B表除ID外有CC和BB两个字段,
id      CC       BB
1         1          1
2         2          1
3         1          2
4         1          3
5         4          3
6         1          4

现在查询A表,查询AA字段值为“1”的,BB字段的所有值,结果:1,2,3
然后查询B表,利用上面A表查询出的BB的值,对B表的BB字段进行查询,取出符合条件的CC字段的值输出,且输出的值不重复,结果:1,2,4
该怎么搞呢???初学者,笨人一个,能想到的方法就是用一个静态变量吧所有查询出来的CC的值串成一个字符串,逗号隔开,后面转成数组再弄……怎么看都不靠谱,求指教,求教导,求包养!!!
------解决思路----------------------
select distinct B.CC from A join B  using(BB) where A.AA=1;
Copy after login
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