mysql只对连接查询中的不同值计数 [英] mysql count only for distinct values in joined query
问题描述
哇!这是一个奇怪的标题,但我很高兴你看,因为我找不到另一种方式说。
我有一张人物表格和一张照片和视频链接表。
我加入了人们的媒体,当然一个人可以有多个媒体。
我试图在一个查询中抓住前30个人和他们的所有媒体,但当我说LIMIT 0,30。当然,我只能得到前30个媒体文件,可能是10个人。
在我进行查询之前,我不知道有多少媒体文件人会有。有没有办法我可以说LIMIT DISTINCT(uid 0,30)????
或类似的东西?
您可以在您的MySQL版本中使用子查询吗?
code> select *
从媒体m
内部连接
(选择uid
从users_tbl
限制0,30)map
在地图上。 uid = m.uid
inner join users_tbl u
on u.uid = m.uid
WOW! That's a weird title, but I'm happy you're looking, cause I couldn't find another way to say it.
I have a table of people and a table of links to photos and videos. I join the people to the media, and of course a person can have more than one piece of media.
I am attempting to grab the first 30 people and all of their media in one query, but when I say LIMIT 0,30. Of course I'll only get the first 30 media files, which could be 10 people.
Before I make the query, I don't know how many media files each person is going to have. Is there a way I can say LIMIT DISTINCT(uid 0,30)????
or something like that?
Can you use subqueries in your version of MySQL?
select * from media m inner join ( select uid from users_tbl limit 0,30) map on map.uid = m.uid inner join users_tbl u on u.uid = m.uid
这篇关于mysql只对连接查询中的不同值计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!