2012年3月25日星期日

anyone good with SQL querries?

I have a query that contains a sub query. The problem is that the sub query
returns more than 1 value so it fails with the error (Subquery returned more
than 1 value). Here is a simplified version of how it is setup.
Select * from table1 where column2 = (select col2 from table2 where column 3
=4)
So for the example below it should return rows 1 and 3 from table 1 since a
and c were returned in the subquery.
table 1
col1 col2
1 a
2 b
3 c
table 2
col1 col2 col3
1 a 4
2 b 2
3 c 4
thanks.
--
Paul G
Software engineer.On Tue, 30 Jan 2007 16:35:00 -0800, Paul
<Paul@.discussions.microsoft.com> wrote:
>I have a query that contains a sub query. The problem is that the sub query
>returns more than 1 value so it fails with the error (Subquery returned more
>than 1 value). Here is a simplified version of how it is setup.
>Select * from table1 where column2 = (select col2 from table2 where column 3
>=4)
>So for the example below it should return rows 1 and 3 from table 1 since a
>and c were returned in the subquery.
>table 1
>col1 col2
>1 a
>2 b
>3 c
>table 2
>col1 col2 col3
>1 a 4
>2 b 2
>3 c 4
>thanks.
Select * from table1 where column2 in
(select col2 from table2 where column 3 >=4)
J.|||thanks that is what I was looking for!
--
Paul G
Software engineer.
"JXStern" wrote:
> On Tue, 30 Jan 2007 16:35:00 -0800, Paul
> <Paul@.discussions.microsoft.com> wrote:
> >I have a query that contains a sub query. The problem is that the sub query
> >returns more than 1 value so it fails with the error (Subquery returned more
> >than 1 value). Here is a simplified version of how it is setup.
> >
> >Select * from table1 where column2 = (select col2 from table2 where column 3
> >=4)
> >So for the example below it should return rows 1 and 3 from table 1 since a
> >and c were returned in the subquery.
> >
> >table 1
> >col1 col2
> >1 a
> >2 b
> >3 c
> >
> >table 2
> >col1 col2 col3
> >1 a 4
> >2 b 2
> >3 c 4
> >thanks.
> Select * from table1 where column2 in
> (select col2 from table2 where column 3 >=4)
>
> J.
>
>

没有评论:

发表评论