using outer query column name in subquery while doing order by

  • using outer query column name in subquery while doing order by caluse

    ex: Select name,id,school from <Student>

    where id in

    (select top 5 id from <Somtable> order by school)

    school name is not present in <Sometable>

    will it work...i experinced this type situation.

    it has worked.

    can any one give reasons..how it is working..?

  • You're basically doing an inner join between <Student> and <School> on ID columns. Are IDs unique across these two tables?

    _____________________________________________________________________
    - Nate

    @nate_hughes
  • Some ids of student table will present in school table...i am not dding inner join..if i go for inner join..will get all rows which were common based on id

  • Please post table definitions, sample data and desired output. Read this to see the best way to post this to get quick responses.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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