Advertisement

02.01.2007 at 02:57AM PST, ID: 22145086
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

SQL Cartesian Problem

Asked by vstack in MS SQL Server, Adobe GoLive HTML Editor

Tags: ,

This could be simple but I am going crazy tring to figure this out.


There are four tables

1. Courses - hold Course data
2. Programs - holds only ProgramID and Program Text
3. Prerequisites - indicates courses that are required before registering for new course
3. Corequisites - indicate courses that you can do along with (at the same time) the new course

Here is my SQL statement:

SELECT  C.CourseID, C.Title, C.Description, C.GoLive, P.ProgramName,
Pr.Prerequisite, Pr.PrerequisiteTracker, Co.Corequisite, Co.CorequisiteTracker
From tblCourses AS C, tblPrograms AS P, tblPrerequisites AS Pr, tblCorequisites AS Co
Where C.CourseID = @courseid
AND C.ProgramID = P.ProgramID
AND Pr.CourseID = C.CourseID
AND Pr.CourseID = Co.CourseID
AND Co.CourseID = C.CourseID

Group By C.CourseID, Pr.PrerequisiteTracker, Co.CorequisiteTracker,  C.Title, C.Description, C.GoLive, P.ProgramName,
Pr.Prerequisite, Co.Corequisite
Order By C.CourseID

Here is what is returned (I have included headers):

CourseID     Title                                Description                                       GoLive                     Prerequisite  PrerequisiteID     Corequisite    CorequisiteID
CMCE1100  Presentations with Power  Improving your presentation skills      0 Communications   CM2200        62                     PP6754         38
CMCE1100  Presentations with Power  Improving your presentation skills      0 Communications   CM3400        63                     PP6754         38
CMCE110   Presentations with Power  Improving your presentation skills      0 Communications   CM2200        62                     RR5432         39
CMCE1100  Presentations with Power  Improving your presentation skills      0 Communications   CM3400        63                     RR5432         39

I don't want all rows returned since there is a duplication in the prerequisite and corequisite data.

Here is the result I want:

CourseID     Title                                Description                                       GoLive                     Prerequisite  PrerequisiteID     Corequisite    CorequisiteID
CMCE1100  Presentations with Power  Improving your presentation skills      0 Communications   CM2200        62                     PP6754         38
CMCE1100  Presentations with Power  Improving your presentation skills      0 Communications   CM3400        63                     RR5432         39



Can you help me out of these Cartesian like dilemma?  I have tried Distinct but it does nothing.

Thank you

Vince

Here are the create table scripts if that helps:

USE [dbContEd]
GO
/****** Object:  Table [dbo].[tblCourses]    Script Date: 02/01/2007 13:54:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblCourses](
      [CourseID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [CourseTrackerID] [int] IDENTITY(1,1) NOT NULL,
      [Title] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [Description] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [ProgramID] [int] NULL,
      [RegularHours] [int] NULL,
      [FastTrackHours] [int] NULL,
      [LabHours] [int] NULL,
      [Tuition] [float] NULL,
      [MaxClass] [int] NULL,
      [MinClass] [int] NULL,
      [DateDeveloped] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [DateRevised] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [Comments] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [OnlineDelivery] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_tblCourses_OnlineDelivery]  DEFAULT ((0)),
      [BlendedDelivery] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_tblCourses_BlendedDelivery]  DEFAULT ((1)),
      [GoLive] [int] NULL CONSTRAINT [DF_tblCourses_GoLive]  DEFAULT ((0)),
 CONSTRAINT [PK_tblCourses] PRIMARY KEY CLUSTERED
(
      [CourseID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

Go

USE [dbContEd]
GO
/****** Object:  Table [dbo].[tblPrograms]    Script Date: 02/01/2007 13:54:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblPrograms](
      [ProgramID] [int] IDENTITY(1,1) NOT NULL,
      [ProgramName] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_tblPrograms] PRIMARY KEY CLUSTERED
(
      [ProgramID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
Go

USE [dbContEd]
GO
/****** Object:  Table [dbo].[tblPrerequisites]    Script Date: 02/01/2007 13:55:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblPrerequisites](
      [CourseID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [Prerequisite] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [PrerequisiteTracker] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_tblPreRequisites] PRIMARY KEY CLUSTERED
(
      [PrerequisiteTracker] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
Go
USE [dbContEd]
GO
/****** Object:  Table [dbo].[tblCorequisites]    Script Date: 02/01/2007 13:55:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblCorequisites](
      [CourseID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [Corequisite] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [CorequisiteTracker] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_tblCorequisites] PRIMARY KEY CLUSTERED
(
      [CorequisiteTracker] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF



Thank

Vince Stack


Start Free Trial
[+][-]02.01.2007 at 03:06AM PST, ID: 18443256

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.01.2007 at 03:07AM PST, ID: 18443260

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, Adobe GoLive HTML Editor
Tags: cartesian, sql
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.01.2007 at 04:44AM PST, ID: 18443621

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42