job.answiz.com
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

Is it possible to fetch data from two tables in sql??

I have two tables:

This is table1:

product_id|product_desc|product_name|product_s_desc

This is table2:

product_price_id|product_id|product_price

Now I want to fetch data from these tables. product_id is same in both tables.

I want to fetch

  1. product_s_desc
  2. product_desc
  3. product_name AND product_price from other table.

Please help me do this.

name
  • 1
Teacher

I'm assuming you have a field named product_price in your second table (you didn't list it):

SELECT t1.product_s_desc, t1.product_desc, t1.product_name, t2.product_priceFROM table1 t1INNERJOIN table2 t2 ON t2.product_id = t1.product_id

You should check out the MySQL manual regarding JOINS, as this is a very basic part of writing SQL queries. You might also consider adding an index on table2 for the product_id field to make the query run faster.

  • 1
Reply Report