Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table,it have no key.
Personel(id,name,family,date,cash)
i insert some records in table with same id,name,family and different date,cash.
now i want to select records from every id which has minimum cash.(not all of records)
select id,name,family,cash from personel (cash must be minimum of specified id)

if i have 2 tables,first one(id,name) and second one(id,date,cash). now how to select id,name,cash like previous question?
what would i do?
work with c# 2010
Posted
Updated 5-Mar-12 13:44pm
v2
Comments
FM7 5-Mar-12 20:00pm    
mr khorshidnia,please reply again,i did not see aswers.thanks
FM7 5-Mar-12 21:54pm    
does anybody have idea?

I hope that your second table has a foreign key linking the data with the first table.
Then use a JOIN on the tables:
SQL
SELECT table1.id, table1.Name, table1.Family, MIN(table2.Cash) as Amount
FROM table1 INNER JOIN table2 ON table1.id=Table2.table1id
Group BY table1.id, table1.Name, table1.Family
 
Share this answer
 
Thi may help you..
1:
SQL
select distinct id, MIN(cash)as Mincash,name,family,dates from Personel group by id,name,family,dates 

2: Second query is same use Join if you know.. on the basis of ID.
 
Share this answer
 
v2
use this query
SQL
select A.id,A.name,min(B.Cash) as Cash from table1 A inner join table2 b on A.id=B.id group by A.id,A.name
 
Share this answer
 
Hi, have you tried:
SQL
select id, name, family, MIN(cash) from personel
GROUP BY id, name, family
 
Share this answer
 
Comments
FM7 5-Mar-12 19:37pm    
if i have 2 tables,first one(id,name) and second one(id,date,cash).
now how to select id,name,cash like previous question?
SQL
with HiMP59 as
(
select dense_rank() over(Partition by Id order by Salary ) as 'MinimumSalary',* from table name)select * from HiMP59 where MinimumSalary=1
 
Share this answer
 

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