Help with Select Statement

  • 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

  • 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 🙂

  • Hi,

    This did the trick !

    What would you call this technique, so I can read up on it ??

    Thanks,

    Matt

  • Hi,

    I think with the search term "subquery" you'll find more examples.

    Regards.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply