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

Whats wrong with this SQL? 2

Status
Not open for further replies.

pgaec

Programmer
Aug 4, 2003
161
AU
MySQL for some reason is not happy with this :

Code:
select * from cr_person where id in  (
	select person1,pereson2,person3,person4,person5,person6 from cr_team where teamid = 1 
)

Executing
Code:
	select person1,pereson2,person3,person4,person5,person6 from cr_team where teamid = 1
gives me 1,2,4,5,6,9

and executing
Code:
select * from cr_person where id in  (
1,2,4,5,6,9
)
seems to be fine too.

But when I put them together, thats when MySQL starts complaining.

Code:
select * from cr_person where id in  (
	select person1,pereson2,person3,person4,person5,person6 from cr_team where teamid = 1 
)

Any ideas?
 
i am not sure that i can help you but im sure if you post an error it will help whoever can... because i don't see a problem with that one...
 
What version of mysql, earlier 4x versions dont support subqueries.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
used in an IN list, the subquery must return no more than a single column

this should work --
Code:
select * 
  from cr_person 
 where id 
    in ( 
       select person1
         from cr_team 
        where teamid = 1
       union 
       select person2
         from cr_team 
        where teamid = 1
       union 
       select person3
         from cr_team 
        where teamid = 1
       union 
       select person4
         from cr_team 
        where teamid = 1
       union 
       select person5
         from cr_team 
        where teamid = 1
       union 
       select person6
         from cr_team 
        where teamid = 1
       )

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top