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
 General SQL Server Forums
 New to SQL Server Programming
 Select Question?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2012-05-09 : 02:21:26
Hi,
I have 2 tables as follows:

CREATE TABLE [dbo].[DrawProgram](
[DrawNumber] [varchar](20) NULL,
[DataRevision] [varchar](20) NULL,
[EventID] [varchar](20) NULL,
[EventDesc] [nvarchar](100) NULL,
[EventDate] [datetime] NULL,
[EventStartDate] [datetime] NULL,
[SpecialEventStatus] [nvarchar](30) NULL,
[EventType] [varchar](20) NULL,
[NevId] [varchar](30) NULL,
[OutComeID] [varchar](20) NULL,
[OutComeTeams] [nvarchar](100) NULL,
[OutComeGameDesc] [varchar](50) NULL,
[OutComeGame] [nvarchar](100) NULL,
[OutComeGameCode] [varchar](50) NULL,
[OutComeDate] [datetime] NULL,
[OutComeStartDate] [datetime] NULL,
[SE] [varchar](10) NULL,
[SpecialGameStatus] [nvarchar](30) NULL,
[SpecialCodeStatus] [nvarchar](30) NULL,
[RecordID] [int] NULL
) ON [PRIMARY]

CREATE TABLE [dbo].[LiveOdds](
[DrawNumber] [varchar](20) NULL,
[OddsRevision] [varchar](20) NULL,
[EventID] [varchar](20) NULL,
[EventDesc] [nvarchar](100) NULL,
[EventStatus] [nvarchar](30) NULL,
[OutComeID] [varchar](20) NULL,
[OutComeDesc] [nvarchar](100) NULL,
[OutComeGame] [nvarchar](100) NULL,
[OutComeGameCode] [varchar](50) NULL,
[OutComeOdd] [varchar](10) NULL,
[RecordID] [int] NULL
) ON [PRIMARY]

I would like to get the max RecordID rows from LiveOdds and join it with DrawProgram table. There might be rows on DrawProgram but not in LiveOdds table. The unique column for both table is OutComeGameCode.
How can I build a SQL statement which has a fast performance?

Best Regards.

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-05-09 : 06:28:20
Please post some sample data.

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page
   

- Advertisement -