User Variables: per-user per-connection SET @varname=expr_value; # := can be used instead of = select @varname; #are case sensitive. integer, real, string, Null values only. SET @sumpop=(Select sum(population) from country); Select name,population,population/@sumpop From country Where population>.1*@sumpop; SET @tenthLargest = (Select surfacearea From country Order By surfacearea Desc Limit 10,1); select @tenthlargest; #Sudan's pop. select sum(surfacearea) from country where surfacearea>=@tenthlargest and name!='antarctica'; set @avgpop=(select avg(population) from country); # value closest to average value: select name,population,abs(population-@avgpop) as deviationAvg from country order by deviationAvg limit 1; Subqueries can accomplish all of the above. cannot be used in Limit :(