Click here to Skip to main content
14,600,878 members
Rate this:
Please Sign up or sign in to vote.
hi
i have two table both have same fields one have two fields different called price and total
i am join both tables and want to fetch some fields from first table and price and total from second table let i have two rows for a particular order then my result shows 4 rows (2+2 from both) but i want only two rows
Posted
Updated 31-Oct-12 21:37pm
v2
Comments
Street Racers 1-Nov-12 2:43am
   
Use "inner join" based on the primary key.
damodara naidu betha 1-Nov-12 3:08am
   
please post your tables design along with sample data.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

First table table1
OrderId,
OrderName,
Date

Second table table2
OrderId,
Price,
Total

Select OrderId, price, total from table1 t1
inner join table2 t2 on t1.Orderid=t2.OrderId


Now this will give me only 3 columns. you can write whatever fields you want like this
   
Comments
Mohamed Mitwalli 1-Nov-12 3:57am
   
5+
damodara naidu betha 1-Nov-12 10:12am
   
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100