locked
How to select top 1 from union? RRS feed

  • Question

  • I want to select top 1 record from the union of two select statement how do i do that. Quesry should be simple without any temp tables.

    select top 1 * from

    (select ccr.rolename from cc_roles ccr union

    select ar.rolename from aspnet_roles ar)

     

    what im doing wrong above. I get

    Msg 102, Level 15, State 1, Line 4

    Incorrect syntax near ')'.

    Tuesday, November 18, 2008 4:59 PM

Answers

  • > what im doing wrong above.

     

    You need an alias for the derived table.

     

    select top 1 * from

    (select ccr.rolename from cc_roles ccr union

    select ar.rolename from aspnet_roles ar) AS t

     

     

    AMB

    Tuesday, November 18, 2008 5:06 PM