Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL syntax help with a subquery
Message
 
 
To
30/11/2006 19:02:12
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows NT
Database:
MS SQL Server
Miscellaneous
Thread ID:
01173944
Message ID:
01173948
Views:
8
Try
SELECT pt.*, ct.b_Name ;
	FROM ParentTable pt ;
	JOIN ChildTable ct ;
		ON pt.a_pk = ct.b_afk ;
	AND b_area = (SELECT MAX(b_area) FROM ChildTable ct2 WHERE ct2.b_pk = ct.b_pk)

	
>
>I'm hoping to get some assistance on a specific SQL query. Here's a simplified version of the two tables it is working off:
>
>Table A (parent)
>a_pk (pk)
>
>Table B (child)
>b_pk (pk)
>b_afk (fk to parent)
>b_area (area)
>b_name (non-unique name)
>
>Problem: I am trying to write a query that returns the name (b_name) of the largest child (b_area) for all parent records.
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform