The table environment defines a float. Floats float, which is to say that they appear in the place which is most aesthetically suitable. You can imagine a big thing like a table or a picture can take up a huge chunk of space. Often, tables are not to be broken across pages and figures almost never can be. As a result, you may find that figures or tables have to be moved onto a subsequent page. In word processors, it is quite common for an enormous gap on the previous page to be left, with the table starting the next page and then more text continuing afterwards. This is not very nice.
To avoid this, you'll probably be familiar with tables and figures sometimes appearing on their own dedicated pages at the end of a chapter. Alternatively, you may find them only appearing at the top and/or bottom of a page, and not necessarily where they would logically go in a document. So, instead of leaving that enormous gap on the previous page, with the table on the next page and then the rest of the text, the first page is filled up with the text that would have followed the table and the table simply gets placed at the top of the next page. Much prettier, much more efficient, but it doesn't work very well if you write something like as can be seen in the table below:
However, because tables often are referred to separately anyway, this floating behaviour is often preferred.
Let me show you what I'm on about.
Instead of this:

Where we have the red text, a huge gap, the table, and then the blue text following on.
We get this:

Where the blue text carries straight on after the red text, the first page is filled up, and then the table appears at the top of the next page, with any further blue text carrying on after it. But all of the first page is filled up nicely.
The table appears in the code between the red paragraphs and the blue paragraphs.
If you would rather avoid this floating behaviour, the first port of call is using the [ht!] option with the table environment. The optional argument is used to tell LaTeX where to place the float. [ht!] will get LaTeX to do the best it can to put the table in the output exactly where it is in the input. However, things like subsection headers can cause problems due to typographical considerations, which I gather is the difficulty you are experiencing.
So the next thing you can do is not float your tables if you don't want them to float! :P One of the purposes of the table environment is to give this floating behaviour. You can just not enclose your tabular within a table environment at all.
However, the table environment is very important and very useful and also does things like captions and the list of tables, which you probably want.
Another thing you can do is simply live with the floating behaviour, which is often aesthetically desirable. Those weaned on Word processors like me are not used to floats and tend to want to avoid them, but they are quite good practice and their benefits are worth bearing in mind.
If, however, you want your document to retain a perfectly logical flow, with each table appearing right where you want to talk about it, you might like to try the placeins package. This defines the \FloatBarrier command, which you can issue after the table environment and it will make sure that nothing which appears after the table environment in the code will appear before the table in the output. Or, in other words, the table will be wherever you want it to be. This may produce ugly results, however, use with caution.
MWE:
\documentclass{article}
\usepackage{placeins}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]
\begin{table}[!ht]
\begin{tabular}{ll}
Column A & Column B \\
1 & 2 \\
3 & 4 \\
5 & 6 \\
7 & 8 \\
9 & 10 \\
11 & 12 \\
13 & 14 \\
15 & 16 \\
17 & 18 \\
19 & 20 \\
21 & 22 \\
23 & 24 \\
25 & 26 \\
27 & 28 \\
29 & 30 \\
31 & 32 \\
33 & 34 \\
35 & 36 \\
\end{tabular}
\end{table}
\FloatBarrier
\lipsum[5-7]
\end{document}
Code for example above:
\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{placeins}
\usepackage[usenames]{color}
\definecolor{red}{rgb}{1,0,0}
\definecolor{blue}{rgb}{0,0,1}
\newcommand{\red}[1]{\textcolor{red}{#1}}
\newcommand{\blue}[1]{\textcolor{blue}{#1}}
\begin{document}
\red{\lipsum[1-4]}
\begin{table}[!ht]
\begin{tabular}{ll}
\toprule
Column A & Column B \\
\midrule
1 & 2 \\
3 & 4 \\
5 & 6 \\
7 & 8 \\
9 & 10 \\
11 & 12 \\
13 & 14 \\
15 & 16 \\
17 & 18 \\
19 & 20 \\
21 & 22 \\
23 & 24 \\
25 & 26 \\
27 & 28 \\
29 & 30 \\
31 & 32 \\
33 & 34 \\
35 & 36 \\
\bottomrule
\end{tabular}
\end{table}
\FloatBarrier
\blue{\lipsum[5-7]}
\end{document}
tableenvironment defines a float. Floats float, which is to say that they appear in the place which is most aesthetically suitable. You can imagine a big thing like a table or a picture can take up a huge chunk of space, and you'll probably be familiar with tables and figures appearing, sometimes, on their own dedicated pages at the back, or only at the top and/or bottom of a page, and not necessarily where they would logically go in a document, right after the first mention of them, because they often are referred to separately anyway. Word processors of course don't do this – Au101 May 30 '16 at 21:35[ht!]option does the most it can to put it in the output exactly where it is in the input, but for typographical reasons, subsection headers may well appear after tables when they are floated using thetableenvironment, either don't use floats, or use a package such asplaceinsto help you – Au101 May 30 '16 at 21:37\labelthe tables and refer to them by \vref (varioref package - highly recomended; and of course the hyperref package). – MaestroGlanz May 30 '16 at 21:40[ht!]won't help,[ht!]is already doing the most you can do with the nativetableenvironment. You can just not enclose yourtabularwithin atableenvironment at all. One of the purposes of thetableenvironment is to give this floating behaviour. However, the environment also does things like captions and the list of tables, which your probably want. Another thing you can do is live with the floating behaviour, which is often desirable. – Au101 May 30 '16 at 21:58placeinspackage. This defines the\FloatBarriercommand, which you can issue before thetableenvironment and it will make sure that nothing which appears before thetableenvironment in the code will appear before the table in the output. Or, in other words, the table will be wherever you want it to be. This may produce ugly results, however, use with caution – Au101 May 30 '16 at 22:00placeinscompletely solved the problem. Thank you so much, please answer to this question so that I can solve it giving you points! – M P May 30 '16 at 22:12