March 26, 2009 at 3:40 pm
Hi Guys,
I am self-teaching SQL statements. Wondering if the following is achievable.
Table with 4 columns, lets call them 1,2,3 and 4
Column 1 contains numeric data, and one row in column 4 contains the character 'X'
What I want is a statement that will return all rows where the value of column 1 is equla or less than the row where column 4 has the 'X'.
Hope that this makes sense. Any help much appreciated.
Matt
March 26, 2009 at 3:51 pm
Hi,
I'm not sure if I understood your question correctly 🙂 but i'll give it a try.
create table tester
(
num int,
my char(1)
)
insert into tester values (1,'')
insert into tester values (2,'')
insert into tester values (3,'X')
insert into tester values (4,'')
-- the query
select * from tester
where num <= (select num from tester where my = 'X')
...assuming you only have one 'X' (you could make thhe "my"-column unique.
Hope that helps 🙂
-----------------------
SQL Server Database Copy Tool at Codeplex
March 26, 2009 at 4:25 pm
Hi,
This did the trick !
What would you call this technique, so I can read up on it ??
Thanks,
Matt
March 26, 2009 at 5:04 pm
Hi,
I think with the search term "subquery" you'll find more examples.
Regards.
-----------------------
SQL Server Database Copy Tool at Codeplex
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply