Mindaugas Jakubauskas
Mindaugas Jakubauskas

Reputation: 439

MySql filter by multiple entries from same table

I have two tables:

entries id | name | entry

filters id | eid | name | value

In first table there are all posts stored and in the second one there is settings for each post. For example:

entries contains 1 | First post | Lorem Ipsum

filters contains

1 | 1 | date_posted | 2013-06-19

2 | 1 | author | admin

3 | 1 | view_count | 578

I need to filter all posts where author is admin and view count is bigger than 300, how could I do it?

Upvotes: 0

Views: 202

Answers (1)

xlecoustillier
xlecoustillier

Reputation: 16351

Try:

SELECT e.id,
       e.name,
       e.entry
FROM   entries e
       LEFT JOIN filters a
              ON a.eid = e.id
                 AND a.name = 'author'
       LEFT JOIN filters v
              ON v.eid = e.id
                 AND v.name = 'view_count'
WHERE  a.value = 'admin'
       AND v.value > 300  

Upvotes: 1

Related Questions