HOW TO Get all the leads and hits of a referer?
Table : hits_log
+-----------+----------+
| topic | referer |
+-----------+----------+
| topic0614 | xxxxxxxx |
| topic0614 | xxxxxxxx |
| topic0615 | zzzzz |
| topic0615 | yyyyyy |
| topic0614 | xxxxxxxx |
| topic0614 | xxxxxxxx |
| topic0615 | zzzzz |
| topic0615 | yyyyyy |
| topic0614 | yyyyyy |
| topic0614 | yyyyyy |
| topic0615 | zzzzz |
| topic0615 | yyyyyy |
+-----------+----------+
Table : leads_log
+-----------+----------+
| topic | referer |
+-----------+----------+
| topic0614 | xxxxxxxx |
| topic0614 | xxxxxxxx |
| topic0614 | xxxxxxxx |
| topic0615 | zzzzz |
| topic0615 | yyyyyy |
| topic0614 | xxxxxxxx |
| topic0615 | zzzzz |
| topic0614 | yyyyyy |
+-----------+----------+
I want the result like this
If search with topic topic0614
+-----------+----------+------------+
| referer | hits | leads |
+-----------+----------+------------+
| xxxxxxxx | 4 | 4 |
| yyyyyy | 2 | 1 |
+-----------+----------+------------+
i have tried
SELECT h.referer, COUNT(h.referer) as hits, COUNT(l.referer) as leads FROM `hits_log` h ,`leads_log` l
WHERE h.topic='topic0614' and h.referer=l.referer
GROUP BY h.referer
but it didn't work
can any one help me out? Thank You.
xxxxxxxxhave 5 leads in your sample output? I only see 4 in theleads_logtable. And why isyyyyyyonly 1, there are 2 in theleads_logtable.xxxxxxxxis only in 4 rows ofhits_log, why do you have5in the results?leads_log, you don't say to only counttopic0614. So my answer counts all matching referers.