Category "posts"

How to show the related categories on sidebar on the category/posts page using php

I have a quote website and it has almost 50 categories, with parent child relationship. What I want is when I open love quote page, on the sidebar it will show

How can I download all tags in the 'Posts' table?

If I write "select Tags from Posts WHERE Tags IS NOT NULL" on site https://data.stackexchange.com I can only download 50,000 rows. How can I get all rows?