下面一个例子我的数据库结构..如何使用WHERE语句在结果上获得完整的GROUP_CONCAT列表?
uid email name
-------------------------------
1 [email protected] John
2 [email protected] Peter
3 [email protected] Colin
书表
book_id book_name
-------------------
1 PHP
2 MySQL
3 Javascripts
4 CSS
历史表
history_uid history_bookid
---------------------------
1 1
1 2
1 3
2 1
2 3
3 3
当前的语句,包括多选择查询上history.history_bookid
SELECT users.uid,
users.email,
users.`name`,
history.history_uid,
history.history_bookid,
GROUP_CONCAT(history.history_bookid) AS BookID,
GROUP_CONCAT(book_name) AS bookTitles
FROM users
INNER JOIN history
ON users.uid = history.history_uid
INNER JOIN book
ON history.history_bookid = book.book_id
WHERE history.history_bookid = 1
OR history.history_bookid = 3
GROUP BY users.uid
个
结果
uid email name history_uid history_bookid BookID bookTitles
---------------------------------------------------------------------------------
1 [email protected] John 1 3 3,1 Javascripts,PHP
2 [email protected] Peter 2 1 1,3 PHP,Javascripts
3 [email protected] Colin 3 3 3 Javascripts
问:
我如何册图书的完整清单被uid = 1
读?示例输出我要的是包括所有的书history table
uid email name history_uid history_bookid BookID bookTitles
---------------------------------------------------------------------------------
1 [email protected] John 1 3 1,2,3 PHP,MySQL,Javascripts
2 [email protected] Peter 2 1 1,3 PHP,Javascripts
3 [email protected] Colin 3 3 3 Javascripts
为什么你有你'WHERE'子句中的过滤器,如果你想每一个结果? – eggyal
@eggyal我使用了选择jQuery:示例http://i.stack.imgur.com/AWRYH.png – user1286499