0

I have two tables in phpmyadmin posts and post_meta and the common column in both tables is post-id.

So I would like to create a query where the results would should post-id, the email (from the post_meta) and title (from posts) Table.

I can get the query to work from individual table i.e i can get the list of all emails from the post_meta table but i can't seem to get the above.

I am trying to use sql query but i have no idea on where to start this.

user38208
  • 1,078
  • 1
  • 15
  • 31

1 Answers1

0

It sounds like what you need to do is a JOIN in your query.

Essentially, you need to try something like this:

SELECT posts.post_id, post_meta.email, posts.title
FROM posts
LEFT JOIN post_meta ON posts.post_id = post_meta.post_id

What this is doing is joining all rows in the post_meta table, to all rows in the posts table, where the post_id field matches.

This is all done dynamically, it doesn't alter your tables etc, but will return a result set giving you the post_id, the email address and the title of the post.

I hope this helps, please add some more detail if I have misunderstood.

BParker
  • 164
  • 2
  • 12