Multiple table rows in one row I have a table from where want to get such classes where 3rd position candidate got more marks than difference of 1st and 2nd. 

class  position  name  total_marks
10     1         a     100
10     2         b     200
10     3         c     150
11     1         d     300 
11     2         e     400
11     3         f     200


I want to write a query to find similar situation in all classes.
Try this query with 2 self joins:

select 
a.class
,a.total_marks as 1st_Position_Marks
,b.total_marks as 2nd_Position_Marks
,c.total_marks as 3rd_Position_Marks
,abs (a.total_marks - b.total_marks) as Difference

from MyTable a
join MyTable b on a.class = b.class and a.position + 1 = b.position
join MyTable c on a.class = c.class and a.position + 2 = c.position

where 
a.position= 1 and b.position=2 and c.position =3 and
c.total_marks &gt; abs(a.total_marks - b.total_marks)


UPDATE. Some explaination.

Basically you are doing calculations on columns, so you need to put data in two columns alongside each other. To do than you need a join, not union. You need to join two rows, that would contain data for your calcultaion. As we need difference between position 1 and 2 we need to put this data on the same row. A.position +1 = B.position does exactly that. as you do not need other permutations of position, I added the filter.