There are a lot of tutorials available that tell you how to accomplish it (like this
] one). However, it only works when you know the number of distinct values on your DocumentName field. If yes, you can go check that tutorial. If not, pivoting the table would not be a good idea in my opinion. If the values on your DocumentName field are dynamic, I suggest just joining the tables on your query and add an additional field where you can put the 'N' and 'Y' values.