If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Can someone help with this SQL join statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-23-10, 08:30
juanc juanc is offline
Registered User
 
Join Date: Dec 2005
Posts: 8
Can someone help with this SQL join statement

Hi

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

wp_posts
ID
post_author
post_date
post_date_gmt
post_content
post_title
post_excerpt
post_status
comment_status
pint_status
post_password
post_name
to_ping
pinged
post_modified
post_modified_gmt
post_content_filtered
post_parent
guid
menu_order
post_type
post_mine_type
comment_count

wp_postmeta
meta_id
post_id
meta_key
meta_value

many thanks for your help
Reply With Quote
  #2 (permalink)  
Old 10-23-10, 09:09
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
Hi,

try the following:

Code:
SELECT ID, post_title, post_excerpt, post_content, meta_value
FROM  wp_posts, wp_postmeta
WHERE wp_posts.post_id = wp_postmeta.post_id
AND meta_key = 'large_download_button'
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 10-23-10, 14:08
juanc juanc is offline
Registered User
 
Join Date: Dec 2005
Posts: 8
Hello thank you very much that worked. I appreciate your help.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On