SELECT * FROM table GROUP BY column WITH ROLLUP --You can avoid getting row name as NULL using grouping, --available from SQL 8.012 --https://www.google.com/search?q=mysql+grouping