Question: At first I thought this may work as a join but I'm not sure if this is really a union command or if even possible. Below is an example of the two tables and each has about 20 more columns of various different data.

**Table 1**

```
>     id    assembly    user1    user2    containerID    productID    packageID
      1     line2       Billy    John     3794           4892         4589
      2     line4       John     Doug     7794           6201         7864

```

**Table 2**

```
>     item_id    name    width    height    weight    flag1    flag2
      3794       Box     10       10        10        0        1
      4892       Lamp    4        6         2         1        1
      7864       BigBox  200      200       300       4        5      

```

What I am trying to do is show all of Table 1 but replace the containerID, productID, and packageID with their name from Table 2 using the matching item\_id. Tried doing this outside of mysql with foreach but with Table 2 having 30k rows it lags up "just a bit" when trying to display the hundreds of rows from Table 1 and replacing each id with its name equivalent.

Answer: 
To see all the table\_1 records, use:

```
   SELECT t1.id, t1.assembly, t1.user1, t1.user2, 
          t2c.name, t2pr.name, t2pk.name
     FROM TABLE_1 t1
LEFT JOIN TABLE_2 t2c ON t2c.item_id = t1.containerid
LEFT JOIN TABLE_2 t2pr ON t2pr.item_id = t1.productid
LEFT JOIN TABLE_2 t2pk ON t2pk.item_id = t1.packageid

```

You can change those to INNER JOINs, but any row that doesn't match all three will not be in the resultset.

My query uses table aliases, because you have to join to the appropriate `TABLE_2` column for each `name` you want to look up.
try to use something like this:

```
  SELECT id, assembly, user1, user2, 
         (SELECT name from table2 where item_id = table1.containerID), 
         (SELECT name from table2 where item_id = table1.productID), 
         (SELECT name from table2 where item_id = table1.packageID)
    FROM table1 
ORDER BY id;

```