Skip to content
Advertisement

How Do I Get The Name From A Different Table Then The One I’m Calling?

I have two tables, one called ordersofitems and one called products.

Now both of these have the column productid, but only my products table has the name associated with it. How would I retrieve the corresponding name for each row?

So far, I have this statement that takes and organizes the table by the productid. All this leaves is to connect it to the names in the products table, but since I’m a beginner, I’m stuck.

I have been researching and have not found anything yet that was “at my level”, so if someone could help me understand it would be fantastic.

SELECT * FROM orderofitems ORDER BY productid ASC

I was assuming something similar to this would work:

SELECT * FROM (SELECT prod_id FROM orderitems ORDER BY prod_id ASC)

Advertisement

Answer

Try this.

SELECT * FROM orderofitems INNER JOIN products ON orderofitems.productid = products.productid;
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement