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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Select stmt : Subquery returned more than 1 value 2

Status
Not open for further replies.

macsql1

Programmer
Jan 20, 2008
25
IN
I have 2 tables

Division Table
DivisionId (Pk, uniqueidentifier,not null)
DivisionName (nvarchar)
DivisionLocation(nvarchar)

Region Table
RegionId (Pk, uniqueidentifier)
RegionName (nvarchar)
RegionManager(nvarchar)
RegiondivisionID (FK,uniqueidentifier,null)


Here i need the name of division table as 'Record of Divisionname' through RegiondivisionID column.

Select Regionname, RegionManager,
'Record of Divisionname' = (select d.DivisionName from Division d, Region r
where r.RegiondivisionID = d.DivisionId)
from Region

Getting this error:-
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Kinldy suggest.

-mac
 
YOu could amend query with a where clause to reduce dataset to one record or you could just do a distinct

(select distinct d.DivisionName from Division d, Region r
where r.RegiondivisionID = d.DivisionId)

Ian
 
Just what the error says. For each record in Region, you are getting zero to many matches in Division. If possible, you might join on more criteria to make the records unique.

If you standard joining logic, you will see this more clearly.

Code:
SELECT RegionName, RegionManager,
d.DivisionName
FROM Region r
LEFT OUTER JOIN Division d ON r.RegionDivisionId = d.DivisionID
 
what is wrong with a join?

Code:
SELECT r.Regionname, r.RegionManager, d.DivisionName AS 'Record of Divisionname' 
  FROM Region as r
  INNER JOIN Division ON r.RegiondivisionID = d.DivisionId
[/oode]

Cheers,
Daddy

-----------------------------------------------------
 What You See Is What You Get
Never underestimate tha powah of tha google!
 
oops

too late :)

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Hey whosrdaddy,

You are also a Star. why am not able to mark you as Star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top