Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 retrieving data from two tables

Author  Topic 

cognos
Starting Member

10 Posts

Posted - 2011-06-01 : 07:50:22
Select odate, amt, snum, cnum
from orders
where amt = (select max(amt)
from orders)
this will show max amt.i want to show cname also.it is another table cust.how can i write query.


ddd

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-06-01 : 07:52:31
join the customers table ona comman column present in both the tables.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-06-01 : 07:56:27
SELECT c.cName, o.odate, o.amt, o.snum, o.cnum
FROM
cust c

INNER JOIN

(
Select <link to cust>,odate, amt, snum, cnum
from orders
where amt = (select max(amt)
from orders)
) o

ON c.<link to cust> = o.linkingfield

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -