Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
pentahari
Starting Member
26 Posts |
Posted - 2009-08-22 : 02:03:49
|
I have two tables that names are subscription and subscriber.Subscription table’s fields are SubscriptionId, subscriptionName.The subscriber table’s fields are Subscriberid, SubscriberName, SubscriptionId.I want the below result using Query:Subscription.SubscriptionId Subscription.SubscriptionName Subscriber.SubscriberId Subscriber.SubscriptionId1 Subscription 1 1 1Null (or) Empty Null (or) Empty 1 1Null (or) Empty Null (or) Empty 1 1 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-08-22 : 03:19:07
|
[code]SELECT Subscription.SubscriptionId, Subscription.SubscriptionName, Subscriber.SubscriberId, Subscriber.SubscriptionIdFROM Subscriber LEFT JOIN Subscription ON Subscriber.SubscriberId = Subscription.SubscriberId [/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
pentahari
Starting Member
26 Posts |
Posted - 2009-08-22 : 04:24:24
|
quote: Originally posted by khtan
SELECT Subscription.SubscriptionId, Subscription.SubscriptionName, Subscriber.SubscriberId, Subscriber.SubscriptionIdFROM Subscriber LEFT JOIN Subscription ON Subscriber.SubscriberId = Subscription.SubscriberId KH[spoiler]Time is always against us[/spoiler]
the subscription table does not have subscriberid field. LEFT JOIN Subscription ON Subscriber.SubscriberId = Subscription.SubscriberId |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-08-22 : 04:32:02
|
then change to SubscriptionId KH[spoiler]Time is always against us[/spoiler] |
|
|
pentahari
Starting Member
26 Posts |
Posted - 2009-08-22 : 04:43:27
|
quote: Originally posted by khtan then change to SubscriptionId KH[spoiler]Time is always against us[/spoiler]
have give wrong results. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-08-22 : 04:47:59
|
pls provide table structure in DDL, sample data in DML and the required result using the [ code ] tag. KH[spoiler]Time is always against us[/spoiler] |
|
|
pentahari
Starting Member
26 Posts |
Posted - 2009-08-22 : 04:50:43
|
quote: Originally posted by khtan pls provide table structure in DDL, sample data in DML and the required result using the [ code ] tag. KH[spoiler]Time is always against us[/spoiler]
/****** Object: Table [dbo].[Subscription] Script Date: 08/22/2009 14:26:24 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[Subscription]( [SubsId] [int] IDENTITY(1,1) NOT NULL, [SubsName] [varchar](30) NOT NULL, [SubsDuration] [int] NOT NULL, [SubsAmount] [money] NOT NULL, [SubsSmallDescription] [varchar](50) NULL, [SubsDetailDescription] [varchar](200) NULL, [SubsFor] [varchar](8) NOT NULL, [SubsEnable] [bit] NOT NULL, CONSTRAINT [PK_Subscription] PRIMARY KEY CLUSTERED ( [SubsId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGO/****** Object: Table [dbo].[Subscriber] Script Date: 08/22/2009 14:26:38 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[Subscriber]( [SubrId] [int] IDENTITY(1,1) NOT NULL, [SubsId] [int] NOT NULL, [EmprId] [int] NOT NULL, [SubrFromDate] [datetime] NOT NULL, [SubrToDate] [datetime] NOT NULL, CONSTRAINT [PK_SubscribedMember] PRIMARY KEY CLUSTERED ( [SubrId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOALTER TABLE [dbo].[Subscriber] WITH CHECK ADD CONSTRAINT [FK_SubscribedMember_Employer] FOREIGN KEY([EmprId])REFERENCES [dbo].[Employer] ([EmprId])GOALTER TABLE [dbo].[Subscriber] CHECK CONSTRAINT [FK_SubscribedMember_Employer]GOALTER TABLE [dbo].[Subscriber] WITH CHECK ADD CONSTRAINT [FK_SubscribedMember_Subscription] FOREIGN KEY([SubsId])REFERENCES [dbo].[Subscription] ([SubsId])GOALTER TABLE [dbo].[Subscriber] CHECK CONSTRAINT [FK_SubscribedMember_Subscription] |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-08-23 : 03:19:30
|
How about some sample data and required result ? KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|
|
|