my sql is a bit rusty (not really that great to begin with!)
I'm trying to write a query that searches through a single table, now within this table there are numerous customers buying some item. Now obviously I can search by the customer, as in
select * from purchases where customer_name "Brian" and product_name like 'Al%;
My problem is what I'm wanting to do is, in a query like that, I want to list all the customer names that have purchased like 'Al%' and the count.
So "Alcohol", etc, would only ever be once per record in the data. But say "Brian" purchases alcohol, all day breakfast, alcohol (all in separate records). I would want to count those, so my return would be "Brian 3".
My final failed attempt was below (not sure it will help!)
select purchases.customer_name, COUNT(purchases.product_name like 'Al%') As Al purchases from purchases;
Thanks in advance. It may be something very simple and I'm totally messing it up in my head!