It is not so much of a 'join' problem as it is a sql query problem. When you use a where clause to locate something in a table the compare that you write needs to have two distinct values to examine. If one of those values contains more than one value such as your strings of "1,2,3" and "14,15,16,17" how do you think a query engine will find the one single value that you want. Comparing a search value of "15" perhaps against your tenid value of "14,15,16,17" will fail. This is true for a where clause as well as an 'on' clause' in other types of joins.
You need to redefine your storage scheme for these "tenid" values. A table that contains each one in its own record that has its rows linked to those records in another table where those specific values all connect to.
My simple example of something would be like this:
John Doe is related to tenids of 1 & 3 & 5. You would create a set of 3 rows in this new table that have the following:
John Doe, 1
John Doe, 3
John Doe, 5
Now when you want to do a query that finds all of the tenids for a record with a key of 'John Doe' you simply do a query that joins the parent table to the tenids table
$q = "select a.name, b.tenid from primary_table a, tenid_table b
where a.name = b.name
order by a.name, b.tenid"