SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Select Query Help?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 05/09/2013 :  08:52:40  Show Profile  Click to see raysefo's MSN Messenger address  Reply with Quote
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

547 Posts

Posted - 05/09/2013 :  12:56:06  Show Profile  Reply with Quote
Does the following query give you what you want?


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


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

India
52325 Posts

Posted - 05/10/2013 :  00:47:18  Show Profile  Reply with Quote

SELECT team, minute and player FROM [dbo].[B] b
WHERE MatchID =(SELECT MAX(MatchID) FROM [dbo].[A])


------------------------------------------------------------------------------------------------------
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 - 05/13/2013 :  09:18:36  Show Profile  Click to see raysefo's MSN Messenger address  Reply with Quote
thank you visakh16.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/14/2013 :  00:38:31  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000