1 Replies - 656 Views - Last Post: 05 December 2014 - 03:22 PM Rate Topic: -----

#1 Datagram   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 06-December 13

SQL Select Statement from many tables

Posted 04 December 2014 - 05:11 PM

Apologies if this is the wrong place to post this, but I'm stumped to how to get around this problem.

I'm having trouble selecting values from multiple tables. I'm selecting all data where the projectID from the Projects table (primary key) is the same as the projectID's from the other tables (foreign keys) and then saving the data in a DataSet, then into an XML file. Everything works in that it selects data, loads it in a DataSet, and then creates the XML file which does contain data, but it's only doing it for the Projects table and ignoring the rest.

The SQL I'm using at the minute is (I'm using C#);
string sql = @"SELECT Projects.projectID, Projects.projectName, Projects.productOwner, Projects.projectOwner
			  FROM Projects
			  INNER JOIN ProductBacklogs
				ON Projects.projectID = ProductBacklogs.projectID
              INNER JOIN Sprints
				ON Projects.projectID = Sprints.projectID
		      INNER JOIN ScrumMasters
				ON Projects.projectID = ScrumMasters.projectID
			  INNER JOIN Developers
				ON Projects.projectID = Developers.projectID
			  WHERE Project.projectID = " + project.projectID;

project.projectID is just the value from the database from another class.

My tables are;
dbo.Projects [projectID, projectName, productOwner, projectOwner]
dbo.ProductBacklogs [userStoryID, projectID, priority, estimate, role, function, reason]
dbo.Sprints [sprintID, projectID, startDate, endDate]
dbo.ScrumMasters [userID, projectID]
dbo.Developers [userID, projectID]

Any help would be great. I'm rubbish at SQL.

Is This A Good Question/Topic? 0
  • +

Replies To: SQL Select Statement from many tables

#2 smendoza88   User is offline

  • D.I.C Head

Reputation: 24
  • View blog
  • Posts: 117
  • Joined: 13-July 11

Re: SQL Select Statement from many tables

Posted 05 December 2014 - 03:22 PM

You're only telling it to return those values.

SELECT Projects.projectID, Projects.projectName, Projects.productOwner, Projects.projectOwner

You're only selecting the above columns, if you want to return more data you have to tell it which columns you want to return.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1