Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 tables,first one(id,name) and second one(id,date,cash).
i insert some records in table with same id and different date,cash.
now i want to select records from every id which has minimum cash.(not all of records)
how to select id,name,cash (cash must be minimum of specified id)

what would i do?
work with c# 2010 and sql2008
Posted

hi you can get ur result by using this query,


SQL
select * from table1 inner join table2 on table1.id =table2.id  where  cash in(select min(cash) from table2)
 
Share this answer
 
Comments
FM7 5-Mar-12 23:53pm    
thanls so much
Hi,
try this one.
SQL
SELECT t1.id,MIN(t2.cash) as [minCash]
FROM tbl1 t1 INNER JOIN tbl2 t2 ON t1.id = t2.id
GROUP BY ID
 
Share this answer
 
Comments
FM7 5-Mar-12 23:53pm    
thanks so much
[no name] 6-Mar-12 0:57am    
welcome
<pre>select t1.ID,t1.Name,t2.Cash from Table_1 t1 inner join Table_2 t2 on t1.ID = t2.ID where cash in(select min(cash) from table_2);</pre>
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900