Home > SQL Development > [Query - General] More INNER JOIN help needed!

[Query - General] More INNER JOIN help needed!



SELECT DISTINCT w.ID, w.WCltID, w.WCltNum, w.WempID, w.Wpdate, w.WEmpLname FROM WIP w INNER JOIN CltBudget c ON w.WCltID<>c.CBudCltID WHERE w.Wpdate >= '12/18/2007' AND w.WcodeSub NOT IN ('IT', 'MKT', 'ABRA','GEN', 'DR', 'MGT') AND w.WCltNum <> '99999'



Ok, the statement above works like 50%. I'm trying to query two different tables in the same DB. I want the records where w.WCltID (in the WIP table) <> c.CBudCltID (in the CltBudget table). It is returning some of the right records but I'd say half of them are incorrect. Many of the records returned exist in w.WCltID and c.CBudCltID, I don't want those records.



Any suggestions?



Thanks for your help!

    
Guest


The <> does not seem to work too well. You might try this:




sql Code:
















Original
- sql Code


  1. SELECT DISTINCT
  2. w.ID, w.WCltID, w.WCltNum, w.WempID, w.Wpdate, w.WEmpLname
  3. FROM WIP w
  4. LEFT JOIN CltBudget c ON w.WCltID = c.CBudCltID
  5. WHERE w.Wpdate >= '12/18/2007' AND w.WcodeSub NOT IN ('IT', 'MKT', 'ABRA','GEN', 'DR', 'MGT') AND w.WCltNum <> '99999' AND c.CBudCtlID IS NULL






This returns records in WIP where there is no match in Cltbudget. Is that what you wanted? If so, give that a try and let me know if it works for ya!

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by ncozzolino
SELECT DISTINCT w.ID, w.WCltID, w.WCltNum, w.WempID, w.Wpdate, w.WEmpLname FROM WIP w INNER JOIN CltBudget c ON w.WCltID<>c.CBudCltID WHERE w.Wpdate >= '12/18/2007' AND w.WcodeSub NOT IN ('IT', 'MKT', 'ABRA','GEN', 'DR', 'MGT') AND w.WCltNum <> '99999'



Ok, the statement above works like 50%. I'm trying to query two different tables in the same DB. I want the records where w.WCltID (in the WIP table) <> c.CBudCltID (in the CltBudget table). It is returning some of the right records but I'd say half of them are incorrect. Many of the records returned exist in w.WCltID and c.CBudCltID, I don't want those records.



Any suggestions?



Thanks for your help!


May not be the most efficient query, but how about:


SQL Code:
















Original
- SQL Code


  1. SELECT DISTINCT ID, WCltID, WCltNum, WempID, Wpdate, WEmpLname
  2. FROM WIP
  3. WHERE WctlID NOT IN (SELECT DISTINCT CBudCltID FROM CltBudget)
  4. AND Wpdate >= '12/18/2007'
  5. AND WcodeSub NOT IN ('IT', 'MKT', 'ABRA','GEN', 'DR', 'MGT')
  6. AND WCltNum <> '99999'



Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by Lauramc
The <> does not seem to work too well. You might try this:




sql Code:
















Original
- sql Code


  1. SELECT DISTINCT
  2. w.ID, w.WCltID, w.WCltNum, w.WempID, w.Wpdate, w.WEmpLname
  3. FROM WIP w
  4. LEFT JOIN CltBudget c ON w.WCltID = c.CBudCltID
  5. WHERE w.Wpdate >= '12/18/2007' AND w.WcodeSub NOT IN ('IT', 'MKT', 'ABRA','GEN', 'DR', 'MGT') AND w.WCltNum <> '99999' AND c.CBudCtlID IS NULL






This returns records in WIP where there is no match in Cltbudget. Is that what you wanted? If so, give that a try and let me know if it works for ya!




YOU ARE THE BEST! It worked!! Thank you for responding so quickly!!!!!!

Was this answer helpful ? Yes No   
Guest


Are there any tutorials on advanced SQL Statements?

Was this answer helpful ? Yes No   
Guest


I use SQL Team sometimes when I have a tough question....

SQL Team

Also if you use the Books Online in SQL Server that can help too. Feel free to stop on by if you have more questions

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved