juanc — 2010-10-23T08:23:16-04:00 — #1
I've got a Wordpress powered site but I've also got a few php pages outside of my WP installation which I need to query the database that powers my WP site. Everything is fine apart from the fact that I don't really know how to write a particular SQL statement which involves a join. I was wondering if someone could help me.
Basically what I want is to be able to get the ID, post_title, post_excerpt, post_content from the wp_posts table and then the meta_value from the table wp_postmeta table but where the meta_key = "large_download_button" and the ID from wp_posts matches the post_id on wp_postmeta
Of course wp_posts.ID and wp_postmeta.post_id are the common fields between the two tables.
These are the two tables wp_posts and wp_postmeta
many thanks for your help
juanc — 2010-10-23T14:04:22-04:00 — #2
Hello thank you very much that worked! I really appreciate your help.
r937 — 2010-10-23T09:52:30-04:00 — #3
let's see how closely the SQL solution matches this requirement statement
<font color='"DeepSkyBlue"'>-- ID, post_title, post_excerpt, post_content from wp_posts </font>
<font color='"deepskyblue"'>-- meta_value from wp_postmeta</font>
FROM wp_posts AS post
JOIN wp_postmeta AS meta
<font color='"deepskyblue"'>-- the ID from wp_posts matches the post_id on wp_postmeta</font>
ON meta.post_id = post.id
<font color='"deepskyblue"'>-- where the meta_key = "large_download_button"</font>
AND meta.meta_key = 'large_download_button'