I have two tables sturctured like so:
Posts Table
id
content
Meta Table
id
post_id
content
name
The posts table is the main parent that can have data from the meta table joined with it
Post Table
id content
1 My first row
Meta Table
id post_id content name
4 1 2011-5-5 date
5 1 My Heading heading
6 2 2012-3-3 date
7 2 My Title heading
How would I write a query to search for an entry in the posts table that contains meta data content of 2011-5-5 with a name of date and My Heading with a name of heading
I can get them individually
Select *
from posts, meta
WHERE post_id = posts.id
AND (name='date' AND content='2011-5-5')
But as soon as I add a second criteria, it returns zero results, becuase we are asking the name field to be two different things
Select *
from posts, meta
WHERE post_id = posts.id
AND (name='date' AND content='2011-5-5')
AND (name='heading' AND content='My Heading')
Any help would be greatly appreciated, Thanks!
You’ll need to join to the table twice: