Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > Databases - MySQL, SQL, Oracle, Access and others
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-29-2005, 07:31 PM   #1 (permalink)
goldfish
Junior Member
 
Join Date: Jul 2005
Posts: 27
Default help with SQL query

Hi,
I am trying to figure out how to write one more sql query. I now have 2 tables, both filled with item numbers and quantities. I want to write queries that will produce what is missing between the two tables. What i need more specifically is a query that looks for item numbers that are in one table and not the other, and vice versa (ie item number 20004 is in our table, but doesn't exist in the other table).

Also a query that prints out discrepancies between quantities for item numbers that do match up (ie item number 20004 is in both tables, but has a quantity of 10 in one and 20 in the other).

I think I need to be using the SQL join functions for these, or is there a better way to do this accomplish this?

thks
goldfish is offline   Reply With Quote
Sponsored Links
Old 09-30-2005, 03:40 AM   #2 (permalink)
cristobal
Senior Member
 
Join Date: Sep 2005
Posts: 219
Default

What you can do is to place all the values of the SQL table1 in an array and then use that to compare with every single on in table2
Then if there is a match print something and when there is not a match print something else.
cristobal is offline   Reply With Quote
Old 09-30-2005, 04:36 PM   #3 (permalink)
kayla
Member
 
Join Date: Jun 2005
Location: Tampa, Fla
Posts: 37
Default

For the first task (rows in one table but not the other) you will need two queries, each featuring a LEFT OUTER JOIN, with a test for IS NULL in the WHERE clause:
Code:
select table1.itemnumber from table1 left outer join table2 on table1.itemnumber = table2.itemnumber where table2.itemnumber is null select table2.itemnumber from table2 left outer join table1 on table2.itemnumber = table1.itemnumber where table1.itemnumber is null
for the second task you will need a simple INNER JOIN:
Code:
select table1.itemnumber , table1.quantity , table2.quantity from table1 inner join table2 on table1.itemnumber = table2.itemnumber where table1.quantity <> table2.quantity
Hope this helps with your needs
kayla is offline   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

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

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 08:57 PM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums