Before reading this blog I expect you are familiar with creating Database and Tables.
STEPS
- Suppose we have a Film Database with two table as TblMovie and TblActor.
- Table structure of TblMovie is
- Table structure of TblActor is
- Lets we have datas in our Table like
- USE [Film]
- GO
- /****** Object: Table [dbo].[TblMovie] Script Date: 05/06/2015 10:21:01 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- SET ANSI_PADDING ON
- GO
- CREATE TABLE [dbo].[TblMovie](
- [MovieId] [int] IDENTITY(1,1) NOT NULL,
- [MovieName] [varchar](50) NULL,
- [ReleaseYear] [varchar](50) NULL
- ) ON [PRIMARY]
- GO
- SET ANSI_PADDING OFF
- GO
- SET IDENTITY_INSERT [dbo].[TblMovie] ON
- INSERT [dbo].[TblMovie] ([MovieId], [MovieName], [ReleaseYear]) VALUES (1, N'My Fair Lady', N'1964')
- INSERT [dbo].[TblMovie] ([MovieId], [MovieName], [ReleaseYear]) VALUES (2, N'Unforgiven', N'1992')
- INSERT [dbo].[TblMovie] ([MovieId], [MovieName], [ReleaseYear]) VALUES (3, N'Time Machine', N'1997')
- SET IDENTITY_INSERT [dbo].[TblMovie] OFF
- /****** Object: Table [dbo].[TblActor] Script Date: 05/06/2015 10:21:01 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- SET ANSI_PADDING ON
- GO
- CREATE TABLE [dbo].[TblActor](
- [MovieId] [int] NOT NULL,
- [FirstName] [varchar](50) NULL,
- [LastName] [varchar](50) NULL
- ) ON [PRIMARY]
- GO
- SET ANSI_PADDING OFF
- GO
- INSERT [dbo].[TblActor] ([MovieId], [FirstName], [LastName]) VALUES (1, N'Rex', N'Harrison')
- INSERT [dbo].[TblActor] ([MovieId], [FirstName], [LastName]) VALUES (1, N'Audrey', N'Hepburn')
- INSERT [dbo].[TblActor] ([MovieId], [FirstName], [LastName]) VALUES (2, N'Clint', N'Eastwood')
- INSERT [dbo].[TblActor] ([MovieId], [FirstName], [LastName]) VALUES (5, N'Humphery', N'Bogart')
- Now we have to join the two tables TblMovie and TblActor on the basis of MovieId
Write SQL Select Statement in the Query Editor
- select * from dbo.TblMovie
Then select the query right click on it and Click
Design Query in Editor like the below Image