it ties to the product ID in the where clause:
WHERE ps4_optiongroups.OptionGroupName = 'Size' AND ps4_productoptions.ProductID = '1'
if you wanted to return more than just the optionName , you will need to edit the select clause:
to include any other columns to return
if you wanted to also use the ProductGroup as a filter, you would need to add that to the where clause.
I'm not going to be able to give you the exact SQL to use for what you are trying to do, I can only give a push in the right direction, using a join query to get related data.
this really isn't supported, if you need exact query help, please sign up for a premiere support appointment.