Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

join two tables

$
0
0

I have two tables with some data in both of them .Im trying to join those tables for expected result  but I didn't get the correct result.Please check below data in both tables

ScheduleTasks

ID Projects CType Empname sstatus sscomments 1 All Projects EF&I Andy, schedule test in schedule 2 Winsphear/Wylie Phase3+ Jim, 3 All Projects EF&I Ray, process test in Process 4 All Projects EF&I Tom Complete test in Comeplte 5 All Projects Phase3+ Tom, 6 All Projects Phase3+ Jim, ST_Phase3 PID ST_ID r1 sratdate enddate rstatus rscomments 1 1 NULL NULL NULL Select 2 2 Phase3+ 2014-04-02 2014-04-04 schedule test in schedule 3 3 NULL NULL NULL Select 4 4 NULL NULL NULL Select 5 5 Phase3+ 2014-05-13 2014-05-14 test test 6 6 Phase3+ 2014-05-07 2014-05-23 test test

from the above tables  I want display only EFI from firsttable  and Phase3+ from secondTable

Select * from ScheduleTasks a full Outer Join ST_Phase3 b
On a.CType = b.CType
And a.ID = b.PID

I tried with full outer join but it shows only  scheduletasks tbale  data

Structure  
CREATE TABLE [dbo].[ScheduleTasks](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ProjectName] [varchar](50) NULL,
	[CType] [varchar](50) NULL,
	[Assign] [varchar](50) NULL,
	[SSStatus] [nchar](10) NULL,
	[SSStatusComments] [nvarchar](max) NULL
 CONSTRAINT [PK_ScheduleTasks] PRIMARY KEY CLUSTERED 


CREATE TABLE [dbo].[ST_Phase3](
	[PID] [int] IDENTITY(1,1) NOT NULL,
	[ST_ID] [int] NULL,
	[CType] [varchar](50) NULL,
	[RequestPStartDate] [datetime] NULL,
	[RequestPEndDate] [datetime] NULL,
	[RequestPStatus] [nchar](10) NULL,
	[RequestPStatusComments] [nvarchar](max) NULL

ALTER TABLE [dbo].[ST_Phase3]  WITH CHECK ADD  CONSTRAINT [FK_ST_Phase3_ScheduleTasks] FOREIGN KEY([ST_ID])
REFERENCES [dbo].[ScheduleTasks] ([ID])
GO
ALTER TABLE [dbo].[ST_Phase3] CHECK CONSTRAINT [FK_ST_Phase3_ScheduleTasks]

expexcting output  from both two tables  in the below .I tried but I didn't get this output.

ID       Projects        CType   Name   ssstatus   sstacomments          rewueststardate          requestenddate    rstatus     estatuscomments 
1	All Projects	EF&I	Andy,	 schedule  test in schedule
2	        	Phase3+ 	                                     2014-04-02 	   2014-04-04       schedule     test in schedule  
3	All Projects	EF&I	Ray,    process      test in Process
4	All Projects	EF&I	Tom      Complete     test in Comeplte
5	  	        Phase3+	                                            2014-05-13 	             2014-05-14      test          test 
6		        Phase3+	                                           2014-05-07      	     2014-05-23      test           test


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>