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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Join Tables

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.SubscriptionId
1 Subscription 1 1 1
Null (or) Empty Null (or) Empty 1 1
Null (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.SubscriptionId
FROM Subscriber
LEFT JOIN Subscription ON Subscriber.SubscriberId = Subscription.SubscriberId
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

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.SubscriptionId
FROM 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
Go to Top of Page

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]

Go to Top of Page

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.
Go to Top of Page

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]

Go to Top of Page

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 ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE 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]

GO
SET ANSI_PADDING OFF



GO
/****** Object: Table [dbo].[Subscriber] Script Date: 08/22/2009 14:26:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE 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]

GO
ALTER TABLE [dbo].[Subscriber] WITH CHECK ADD CONSTRAINT [FK_SubscribedMember_Employer] FOREIGN KEY([EmprId])
REFERENCES [dbo].[Employer] ([EmprId])
GO
ALTER TABLE [dbo].[Subscriber] CHECK CONSTRAINT [FK_SubscribedMember_Employer]
GO
ALTER TABLE [dbo].[Subscriber] WITH CHECK ADD CONSTRAINT [FK_SubscribedMember_Subscription] FOREIGN KEY([SubsId])
REFERENCES [dbo].[Subscription] ([SubsId])
GO
ALTER TABLE [dbo].[Subscriber] CHECK CONSTRAINT [FK_SubscribedMember_Subscription]
Go to Top of Page

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]

Go to Top of Page
   

- Advertisement -