Answers
MySQL 数据库允许 group 的时候选用非 group 字段
但是取的是不是第1个不是很清楚
select project_id, pic_url
from pics
where pic_url is not null
group
by project_id
;
不过既然有自增型的ID
可以用
min(id)
找到符合条件的最小 id,再连接查询得到需要的数据
select b.*
from (
select project_id, min(id) as id
from pics
where pic_url is not null
group
by project_id
) a
left join pics b on a.id = b.id
;
kenk3
answered 9 years, 4 months ago