Reputation: 87
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
product_s_desc
product_desc
product_name
AND product_price
from other table.Please help me do this.
Upvotes: 3
Views: 36182
Reputation: 3177
SELECT t1.*,t2.product_price
FROM table1 t1,table2 t2
WHERE t1.product_id=t2.product_id
Upvotes: 1
Reputation: 1
$sql = "SELECT Student.First_Name,Student.Last_name,Student.Mobile_No,Student.Email,Student.Institue,Student.DOB,Student.Gender
Address.Address_Line1,Address.City,Address.State,Address.Country,Address.Zip_code
FROM Student INNER JOIN Address
ON Student.Id=Address.Id;";
Upvotes: -4
Reputation: 8889
Select * from table1 join table2 on table1.productid = table2.productid
Upvotes: 1
Reputation: 9860
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_price
FROM table1 t1
INNER JOIN 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.
Upvotes: 6