Sql查询显示一列中的许多值

时间:2018-02-18 14:42:08

标签: php mysql sql phpmyadmin

列t.name(流派)显示许多相同的值我试图让它工作但我没有成功..

这是我的SQL

select o.id, b.title, a.firstName, a.lastName, 
        b.noOfPages, b.price, group_concat(t.name) as 'genre'
from author a,book_author ba, book_type bt,orders o,type t, book b, order_list ol
where ol.book_fk = b.id 
and bt.book_fk = b.id 
and bt.type_fk = t.id 
and ba.author_fk = a.id 
and ba.book_fk = b.id 
and ol.orders_fk = '74' 
GROUP BY ol.id

图片enter image description here

图片用于显示列类型查询返回的值数

1 个答案:

答案 0 :(得分:1)

我相信你关注你的类型专栏中“犯罪”的重复价值。 尝试在group_concat中使用distinct。

select o.id, b.title, a.firstName, a.lastName,b.noOfPages, b.price,
group_concat(distinct t.name) as 'genre' from author a,book_author ba,
book_type bt,orders o,type t, book b, order_list ol where ol.book_fk = b.id
and bt.book_fk = b.id  and bt.type_fk = t.id and ba.author_fk = a.id
and ba.book_fk = b.id  and ol.orders_fk = '74' GROUP BY ol.id;