Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2005, 05:55 PM
Authorized User
 
Join Date: Jun 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rylemer Send a message via MSN to rylemer Send a message via Yahoo to rylemer
Default Inner Join Problem

hi! to all.

Sorry for the previous post I accidentally hit enter.
this is the original post.


I have 2 table I called it. tbl_1 and tbl_2.

I use inner join to list all the records that are match in tbl_1 and tbl_2
I want the result to show all the records that not match in tbl_1 and tbl_2

below is the list of table that I am using.

tbl_1
-------------------------
ProductID | Product
-------------------------
PH1 | Mouse
PH2 | KeyBoard
PH3 | Monitor
PH4 | CPU
PH5 | Headset

tbl_2
--------------------------
ProductID | Product
--------------------------
PH1 | Mouse
PH2 | KeyBoard
PH3 | Monitor
PH6 | CDROM
PH7 | Video Card

this is my SQL stament
================================================== =============
SELECT tbl_1.ProductID, tbl_1.Product
FROM tbl_1 INNER JOIN tbl_2 ON tbl_1.ProductID=tbl_2.ProductID;
================================================== ===============

---------------------
ProductID | Product
---------------------
PH1 | Mouse
PH2 | KeyBoard
PH3 | Monitor

Result I want to achieve.

---------------------
ProductID | Product
---------------------
PH6 | CDROM
PH7 | Video Card


hope you can help me with this problem.

Thanks,
Rylemer
 
Old October 20th, 2005, 01:13 PM
Authorized User
 
Join Date: Oct 2005
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To get the records in table2 that are not in table1, you can do the following:

SELECT tbl_2.ProductID, tbl_2.Product
FROM tbl_2 LEFT OUTER JOIN tbl_1
  ON tbl_1.ProductID=tbl_2.ProductID
WHERE tbl_1.ProductID IS NULL

Regards,
SQL Server Helper
http://www.sql-server-helper.com

 
Old October 21st, 2005, 04:41 PM
Authorized User
 
Join Date: Jun 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rylemer Send a message via MSN to rylemer Send a message via Yahoo to rylemer
Default

sshelper,

Cool It worked thanks for you help.

Thanks,
Rylemer






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Join/Where jpryor SQL Server 2005 2 April 12th, 2008 01:25 AM
inner join problem john-boy SQL Language 1 March 29th, 2006 06:30 AM
Oracle 8i inner join and left join problem puteri_84 Oracle 2 August 19th, 2004 07:14 AM
JOIN problem kaz SQL Language 4 December 22nd, 2003 04:13 PM
SQL Inner Join Problem tp194 Classic ASP Databases 2 July 8th, 2003 09:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.