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 April 21st, 2010, 07:02 AM
Registered User
 
Join Date: Aug 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Extracting information problems

Morning all, I have limited experience with SQL Server, and I have to ask for help as I am unsure how to proceed and I have my client breathing down my neck.

Let me explain. I have membership table that contains a reference to membership categories. A Member can have multiple categories. Table structure is as follows:

**** TABLE NAME = MasterList ****
RecordID INT Auto
FirstName varchar(80)
LastName varchar(80)
There are more than this but is irrelevant at for this problem. The assigned categories table is as follows

**** TABLE NAME = Member_Assigned_Categories ****
MemCatID Int Auto
RecordID int
CatID int

I have another table of category descriptions, that begins with the CatID.

I have some example data:
Table MasterList:
56 Steve Johnson
57 Vince Jeffreys
58 Matt Slone

Table Member_Assigned_Categories:
67 | 58 | 2
68 | 57 | 22
69 | 58 | 22
70 | 56 | 9
71 | 58 | 6

I need to extract all the records from the materlist table that are assigned to categories 2 and 7. How would run write the SQL statement to do this.

I tried this:
Code:
SELECT COUNT(*) AS MemberCount FROM MasterList INNER JOIN  Member_Assigned_Categories ON  MasterList.RecordID=Member_Assigned_Categories.RecordID WHERE  Member_Assigned_Categories.CatID = 6 AND  Member_Assigned_Categories.CatID = 22;
and this:
Code:
SELECT COUNT(*) AS MemberCount FROM MasterList INNER JOIN  Member_Assigned_Categories ON  MasterList.RecordID=Member_Assigned_Categories.RecordID WHERE  Member_Assigned_Categories.CatID IN(6, 22);
But they never worked. I think I need to group the results or have a nested SQL statement. Please help, I am unsure how to resolve this.
Many thanks for your help with this matter

Paul
[email protected]

Last edited by neojakey; April 21st, 2010 at 08:33 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting attribute value hag XSLT 1 March 3rd, 2008 03:16 AM
extracting atributes - how to do this? zoreli XML 6 August 12th, 2006 03:46 AM
Help!! extracting information from an email Ivan83sg J2EE 2 March 1st, 2005 04:19 AM





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