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
 General SQL Server Forums
 New to SQL Server Programming
 Subquery Question

Author  Topic 

yalgaar
Starting Member

43 Posts

Posted - 2006-02-25 : 11:15:35
I want to run a subquery, example is below:

select id from XYZ where name like '%yalgaar%' or where name like '%yamaha%'

The above statement will return multiple rows. I want to run the above query is a subquery for another SQL Select statement.

Select * from funny where ( subquery that reurns multiple rows)

When I run the above query, I get an error message below:

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

Kristen
Test

22859 Posts

Posted - 2006-02-25 : 12:13:46
Something like this?

Select *
from funny
where funny.ID IN
(
select id
from XYZ
where name like '%yalgaar%'
or where name like '%yamaha%'
)

Kristen
Go to Top of Page

yalgaar
Starting Member

43 Posts

Posted - 2006-02-25 : 13:14:00
Awesome!!! it worked like a charm :-)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-02-25 : 13:56:06
"it worked like a charm"

I guess I got lucky!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-27 : 03:26:25
With small change
quote:
Originally posted by Kristen

Something like this?

Select *
from funny
where funny.ID IN
(
select id
from XYZ
where name like '%yalgaar%'
or where name like '%yamaha%'
)

Kristen



Madhivanan

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

- Advertisement -