in reply to query linking

Thanks to monarch we now have a more legible form of your question. But what do you mean exactly by "linking" the two sql queries? What does "this is not happening" mean to you? Did your script throw any errors? If so, which ones? Did it produce unexpected output? If so, what was it and what did you expect?

So many questions ...

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James