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 2008 Forums
 Transact-SQL (2008)
 Select Query Help?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2013-05-09 : 08:52:40
Hi,

I have 2 tables(Table A and Table B)

CREATE TABLE [dbo].[A](
[MatchID] [nvarchar](100) NULL,
[DrawName] [nvarchar](100) NULL,
[MatchCode] [nvarchar](100) NULL,
[SpecialEventCode] [nvarchar](100) NULL,
[TeamNames] [nvarchar](100) NULL,
[StartDate] [datetime] NULL,
[Round] [nvarchar](100) NULL,
[Status] [nvarchar](50) NULL,
[StatusID] [nvarchar](50) NULL
) ON [PRIMARY]


CREATE TABLE [dbo].[B](
[MatchID] [nvarchar](100) NULL,
[MatchCode] [nvarchar](100) NULL,
[SpecialEventCode] [nvarchar](100) NULL,
[IncidentID] [nvarchar](100) NULL,
[Team] [nvarchar](10) NULL,
[Minute] [nvarchar](10) NULL,
[Score] [nvarchar](50) NULL,
[deleteInfo] [nvarchar](10) NULL,
[Player] [nvarchar](100) NULL
) ON [PRIMARY]


Here are some sample data for Table A:

11775120 841 533 20 ZENIT - ANJI MAHAÇQALA 2013-05-08 20:30:00.000 T?k Oyun Qurtardi 6
11714772 715 589 21 LIVERPUL - SANDERLEND 2013-01-02 23:45:00.000 21-ci Tur Qurtardi 6
11714775 715 566 20 SAUTQEMPTON - ARSENAL 2013-01-01 21:30:00.000 21-ci Tur Qurtardi 6


Here are some sample data for Table B:

11775120 533 20 3149133 2 35 0 - 0 0 Yuri Zhirkov
11775120 533 20 3149231 1 45 0 - 0 0 Roman Shirokov
11775120 533 20 3149465 1 65 0 - 1 0 Tomas Hubocan
11775120 533 20 3149586 1 83 0 - 1 0 Neto
11775120 533 20 3149657 2 90 0 - 1 0 Vladimir Gabulov
11714772 589 21 2803609 2 60 3 - 0 0 James McClean


I would like to get the team, minute and player from Table B which has the max matchid.

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-05-09 : 12:56:06
Does the following query give you what you want?

[CODE]
SELECT team, minute and player FROM [dbo].[B] B1,
(SELECT MAX(MatchID) as mmax from [dbo].[B]) as T WHERE B1.MatchID= T.mmax;
[/CODE]

Just curious why do you need Table A just to get the team, minute and player from Table B which has the max matchid.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-10 : 00:47:18
[code]
SELECT team, minute and player FROM [dbo].[B] b
WHERE MatchID =(SELECT MAX(MatchID) FROM [dbo].[A])
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2013-05-13 : 09:18:36
thank you visakh16.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-14 : 00:38:31
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -