I have two tables - table1 and table2. Both contains two columns - rollnum,name. Now I wants to select all rows from table1 and randomly 5rows from table2. I have written like this
select rollnum,name from table1 union (select top 5 rollnum,name from table2 order by NEWID())
but it shows an error ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.
please help . I think the mistake is at NEWID(). here rollnum is primary key