I have a database and want to select from mysql a result which could not succeed after one month please help me it would be really appreciated!
My Database Table looks like below and Name = Customer
Id customer_id customer_name Date Books_bought
1 1 Alex 08.06.2017 HarryPotter1
2 1 Alex 08.06.2017 Harry Potter2
3 1 Alex 09.06.2017 PHP 7
4 2 Sam 10.06.2017 SQL
I want to display the following:
- What books Alex bought on 08.06.2017 – Harry Potter1 and Harry Potter 2
- In another table row that Alex on 09.06.2017 bought only PHP 7
- In another table row another customer Sam on 10.06.2017 bought SQL
However, the result return all books for one customer Alex which has customer_id=1 and the reset users result are the same
My current html and php Table looks like below:
Id customer_id customer_name Date Books_bought
1 1 Alex 08.06.2017 HarryPotter1
Harry Potter2
PHP 7
SQL
---------------------------------------------------------------------------
2 1 Alex 09.06.2017 HarryPotter1
Harry Potter2
PHP 7
SQL
-------------------------------------------------------------------------
3 2 Sam 10.06.2017 HarryPotter1
Harry Potter2
PHP 7
SQL
Best Answer
You seem to want to
GROUP BY
customer and date; and I guess that you want to concatenate the books.This would do it:
Check:
GROUP_CONCAT
GROUP BY
dbfiddle here