Hello,
First, if I look your sql request you only get the product id, so I don't really understand why you don't use Mohmed request in his previous post ?
Second step, important to note for what you want achieved, if I understand you well you want have all user cms id, or let's say it differently joomla user id, but customers in guest mode haven't any joomla user id...
The Mohamed solution will give what you requested but just not for guest customer.
If that fit your needs you have here the solution, if you want more, I suggest that you precise your need and the use context.
regards