vrv333 Posted March 20, 2014 Share Posted March 20, 2014 Hello Guys I am new to SQL and Need your help regarding SQL code to get data from below table. MATERIAL PLANT M101 E15 M101 B44 M102 E15M102 B55 M103 E15 M103 B01 M104 E15 M105 E15 M106 E15 M106 B44 M106 B01 My SQL Output should be M104 E15 M105 E15 Basically we want to identify materials that are only exclusive to E15. If the material is in any other plants we don’t want the material in the output. I appreciate all your help Thanks Link to comment Share on other sites More sharing options...
davej Posted March 20, 2014 Share Posted March 20, 2014 See... http://www.w3schools.com/sql/sql_where.asp Link to comment Share on other sites More sharing options...
vrv333 Posted March 20, 2014 Author Share Posted March 20, 2014 Hi Using Where Clause is bringing all the materials in E15. But I want materials that are in Plant E15 but not in another plants. Is there any way that i could apply that restriction? Link to comment Share on other sites More sharing options...
vrv333 Posted March 20, 2014 Author Share Posted March 20, 2014 Hi All I got my answer with below SQL statement. Thanks to everyone SELECT MaterialNumber from TABLE MaterialBranchMasterEDW WHERE BranchNumber = 'E15' and MaterialNumber not in (SELECT MaterialNumber from MaterialBranchMasterEDW where BranchNumber <> 'E15') Link to comment Share on other sites More sharing options...
davej Posted March 20, 2014 Share Posted March 20, 2014 Sorry, I did not read your question carefully enough. Your sub-query is a good approach. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now