I'm trying to filter user and friends' post by month.
This is the structure of my tables:
Friends
id username friend
1 kyle jan
2 jan kyle
3 kyle nic
4 nic kyle
Posts
id title username date
1 hello world kyle 2015-01-02
2 hola mundo jan 2015-02-02
3 como estas nic 2015-02-03
This is what I've tried so far:
SELECT DISTINCT(p.title), p.date, p.username
FROM posts AS p
LEFT JOIN friends AS f
ON
p.username = f.username
OR p.username = f.friend
WHERE p.username = 'kyle'
AND MONTH(p.date) = 1
OR f.username = 'kyle'
OR f.friend = 'kyle'
But the result still gets all those posts and not filtered. Any ideas?
UPDATE: Please check my sqlfiddle http://www.sqlfiddle.com/#!2/9980d/2