Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT IN A SELECT IN A SELECT (possible?)

Status
Not open for further replies.

apexearth

Programmer
Apr 5, 2010
13
US
I'm trying to put a select within a select within a select.

Here's an example of what I'm trying to do.

Code:
DECLARE @TEMP TABLE (I INT, K INT)
INSERT INTO @TEMP
SELECT 1, 2 UNION SELECT 1, 3 UNION SELECT 1, 5 UNION
SELECT 2, 1 UNION SELECT 2, 3 UNION SELECT 2, 7 UNION
SELECT 3, 3 UNION SELECT 3, 3 UNION SELECT 3, 2

--Can I somehow make this work?
SELECT 	(  SELECT MAX(J) FROM (SELECT MIN(K) AS J FROM @TEMP B GROUP BY I)  ) FROM @TEMP A
 
I figured this out. The inner needs a name in order to succeed.

Code:
SELECT     (  SELECT MAX(J) FROM (SELECT MIN(K) AS J FROM @TEMP B GROUP BY I) as whatever) FROM @TEMP A
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top