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



Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

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 Codewalkers Forums Sponsor:
Old January 29th, 2013, 07:54 AM
VincentasG VincentasG is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 34 VincentasG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 5 sec
Reputation Power: 1
Comparing mySQL Tables

Hi,

I have two tables that I want to compare.
One is a temporary table that includes the product id, quantity, retail price and wholesale price (product feed from my supplier).
The other is a permanent table that includes among other things the same product id.
I want to see if an id is in the temp table and not the other one (meaning it's a new product).
I also want to see if an id is in the permanent table and not in the temp table (meaning it's a discontinued product).
I'd like to be able to output these to the web page so that I can address them.
I've searched and I'm getting all kinds of different ideas around the web.

Can anyone point me in the right direction? Some sample code, a link, a kick in the right direction - any and all answers are much appreciated.

Thanks

Reply With Quote
Old January 29th, 2013, 01:51 PM
IAmALlama IAmALlama is offline
Me
Click here for more information
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,267 IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 30 m 38 sec
Reputation Power: 9
if you want to find where id exists in both tables you can do an inner join query. the result will hav eonly rows where the id exists in both tables. to find where an id exists in only 1 table, you can do a left join where the second table join key is null. here are some examples:

given the structure you specified using "temp" for the temp table and "permanent" for the permanent table name. you will of course need to change the names.

exists in both:
Code:
SELECT product_id
FROM permanent
    INNER JOIN temp
        ON permanent.product_id=temp.product_id


exists only in permanent, not in temp
Code:
SELECT product_id
FROM permanent
    LEFT JOIN temp
        ON perment.product_id=temp.product_id
WHERE
    temp.product_id IS NULL


reverse above, only in temp, not in permanent
Code:
SELECT product_id
FROM temp
    LEFT JOIN permanent
        ON perment.product_id=temp.product_id
WHERE
    permanent.product_id IS NULL

Reply With Quote
Old January 30th, 2013, 12:37 AM
VincentasG VincentasG is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 34 VincentasG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 5 sec
Reputation Power: 1
Thanks a lot!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Comparing mySQL Tables


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 - 2013, Jelsoft Enterprises Ltd.

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