Heim  >  Artikel  >  Backend-Entwicklung  >  MSQL取不重复数据,新手求教

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

WBOY
WBOYOriginal
2016-06-23 13:48:45802Durchsuche

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;

select distinct B.CC from A join B  using(BB) where A.AA=1;


学习了!!!谢谢
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn