May i use anything else instead of "IN" clause?

  • SELECT A.Name

    FROM Students

    WHERE

    A.No IN (22,34,12,67)

    Hi Guys,

    In above query i am using "IN" clause to find out Student No. but some time no. of find are very large.

    Is there any other option then "IN". can i use anything else instead of "IN"?

    Thanks in Advance.

    Pravin Patel.

  • Pravin Patel-491467 (11/24/2009)


    SELECT A.Name

    FROM Students

    WHERE

    A.No IN (22,34,12,67)

    Hi Guys,

    In above query i am using "IN" clause to find out Student No. but some time no. of find are very large.

    Thanks in Advance.

    Pravin Patel.

    Your requirement is not clear enough. But if you dont want to hardcode the values in there, u can do something like this,

    SELECT A.Name

    FROM Students

    WHERE

    A.No IN (SELECT ID FROM <TABLE> WHERE <<YOUR CONDITION>>)

    Is there any other option then "IN". can i use anything else instead of "IN"?

    Plenty of options but depends what you want to do!

    ---------------------------------------------------------------------------------

  • Or if those are the student id's that you need, just put more filters in there using the AND keyword.

    So it would be something like..

    WHERE StudentId IN(1,2,3,4)

    AND StudentName LIKE '%Tom%'

    AND StudentGrade IN('G1', 'G2')

    AND (SchoolDept <> '2' OR SchoolDept NOT IN('10','7','8','9')

    --
    :hehe:

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

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