Jim R Posted August 12, 2011 Share Posted August 12, 2011 I can't seem to wrap it around my head how to get a desired result from querying two tables. I get two or multiple columns but not when it involves two tables. It's a WordPress query. I'm trying to: SELECT name FROM wp_terms WHERE (this is where I stumble)... where taxonomy from wp_term_taxonomy = post_tag AND term_id from wp_term_taxonomy = term_id from wp_teams Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/ Share on other sites More sharing options...
trq Posted August 12, 2011 Share Posted August 12, 2011 You'll want to do a few tutorials on JOINs. Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256300 Share on other sites More sharing options...
Jim R Posted August 12, 2011 Author Share Posted August 12, 2011 As I said, I'm not really able to wrap my head around it. Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256458 Share on other sites More sharing options...
trq Posted August 12, 2011 Share Posted August 12, 2011 So you want us to write you another one? What don;t you understand? What code have you tried? What errors are you getting? Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256469 Share on other sites More sharing options...
fenway Posted August 12, 2011 Share Posted August 12, 2011 Post the two table structures, and we'll give you a hand. Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256470 Share on other sites More sharing options...
Jim R Posted August 12, 2011 Author Share Posted August 12, 2011 That is the table structure as best as I can tell. The two tables are wp_term and wp_term_taxonomy. I'm trying to extract results from "name" in wp_term, where "taxonomy" in wp_term_taxonomy is post_tag, matching them by "term_id", which is in both tables. Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256479 Share on other sites More sharing options...
fenway Posted August 12, 2011 Share Posted August 12, 2011 select wp.term.name from wp_term inner join wp_term_taxonomy using ( term_id ) Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256582 Share on other sites More sharing options...
Jim R Posted August 12, 2011 Author Share Posted August 12, 2011 That just prints all the term. I'm trying to get the ones that just have post_tag as their taxonomy. I tried this, but I get a syntax error. SELECT wp_terms.name FROM wp_terms INNER JOIN wp_term_taxonomy USING (term_id) WHERE wp_term_taxonomy.taxonomy IS (post_tag) Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256641 Share on other sites More sharing options...
Jim R Posted August 12, 2011 Author Share Posted August 12, 2011 Got it. Thanks. SELECT wp_terms.name FROM wp_terms INNER JOIN wp_term_taxonomy USING (term_id) WHERE wp_term_taxonomy.taxonomy = 'post_tag' Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256647 Share on other sites More sharing options...
Jim R Posted August 13, 2011 Author Share Posted August 13, 2011 Continuing with this project, I need to alter a column in one table based on what it matches in the other. tables are: wp_term_taxonomy_test wp_term_taxonomy UPDATE wp_term_taxonomy_test SET wp_term_taxonomy_test.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id WHERE wp_term_taxonomy.term_id = wp_term_taxonomy_test.term_id The error I'm getting is that wp_term_taxonomy.term_id doesn't exist. However, it does exist. Error Code : 1054 Unknown column 'wp_term_taxonomy.term_id' in 'where clause' Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1256695 Share on other sites More sharing options...
fenway Posted August 14, 2011 Share Posted August 14, 2011 You'll need a similar JOIN -- you haven't reference the second table. Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1257190 Share on other sites More sharing options...
Jim R Posted August 15, 2011 Author Share Posted August 15, 2011 Ooops...sorry. I had figured that out but didn't follow up. Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/244562-results-by-querying-two-different-datatables/#findComment-1257530 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.