Still learning MySQL, so bear with me.
So I have two tables: leads, which is:
id dat in_click_id
55 2011-08-15 400
10 2011-08-13 400
34 2011-08-13 420
50 2011-08-12 420
15 2011-08-14 425
The second table is called in_clicks:
id location keyword
400 KS word1
410 CO word2
415 LA word2
420 CA word2
425 FL word3
So I am trying to find out if a lead was associated with an in click.
In other words, I am trying to get the following:
keyword count(keyword)
word1 15
... ...
So the keyword will be the word, and the second column
will the aggregate number of leads from that keyword.
Since the data is in two separate tables, I need to use the join command, but
I’m having some issues implementing it.
Here’s one of my many attempts, which obviously doesn’t work.
SELECT id, discriminator, create_date, in_click_id, COUNT(in_click_id)
FROM leads
WHERE create_date LIKE '%2011-08-17%'
ORDER BY COUNT(in_click_id) DESC
INNER JOIN in_click ON leads.in_click_id = in_clicks.id;
Help!?
You need to use GROUP BY, like this: