SQL Basics

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old January 24th, 2013, 10:54 PM
PHPjoe PHPjoe is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 PHPjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 8 sec
Reputation Power: 0
Finding items from one table that don't exist in another table

Hi,

OK, I hope I will explain this clearly,
I have three tables:
1. wp_posts
2. wp_postmeta
3. companies

wp_posts stores information about the post.
wp_postmeta stores information like custom fields of the post.
companies is a table that gets updated daily with current companies, so if a company is no more our client then they will get deleted from the companies table.

Now, wp_posts and wp_postmeta share post_id and wp_postmeta and companies share company_id, however, wp_postmeta stores company_id as a char while companies stores company_id as an int.

I would like to find all the company_id that exist in wp_postmeta but don't exist in companies and then change their post_status in wp_posts from publish to draft.

I hope that's clear,
Thanks!

Reply With Quote
  #2  
Old January 25th, 2013, 04:14 PM
PHPjoe PHPjoe is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 PHPjoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 8 sec
Reputation Power: 0
So far to find the none existing company_id's I have this:

SELECT p . *
FROM wp_postmeta p
LEFT JOIN companies c ON p.meta_value+0 = c.company_id
WHERE c.company_id IS NULL
AND p.meta_key = 'company_id'
ORDER BY p.meta_value

Now I need to update the status in wp_posts of those companies that are in wp_postmeta table but not in companies table

Last edited by PHPjoe : January 25th, 2013 at 04:17 PM.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Finding items from one table that don't exist in another table


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap