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 2000 Forums
 Transact-SQL (2000)
 Select within a Select

Author  Topic 

bluemetal
Starting Member

26 Posts

Posted - 2005-08-05 : 02:09:32
Hi, can i do something like the following?

Select t.Owner_id, t.Name, t.Phone, (Select Vehicle from Vehicles where vehicle_owner = t.owner_id) as Vehicle_Driven
From Table t

? i get a Not a Group By expression right at the SELECT within the Select (near the start of bracket).. what am i doing wrong?

Thanks!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-05 : 02:35:15
It seems correct. Make sure inner Select does not return more than one value


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-05 : 04:54:34
I reckon MAD has the answer.

Try

(Select TOP 1 Vehicle from Vehicles where vehicle_owner = t.owner_id)

instead?

Mind you, if that fixes it, you need to worry about WHICH Vehicle you actually want to show - the MAX? MIN? TOP 1? TOP 1 with ORDER BY?

Kristen
Go to Top of Page
   

- Advertisement -