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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 MAX ()

Author  Topic 

Gigabyte
Starting Member

30 Posts

Posted - 2012-06-14 : 19:48:30
Table A
pid pname
1 pen
2 pencil
3 paper

Table B
pid price
1 10
2 25
3 63
3 32
3 44
2 22
1 21


I need to find pid and price of the product which is the highest among all the products from Table A and Table B


GIGABYTE+

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-14 : 22:40:42
[code]
SELECT a.pname,n.price
FROM TableA a
INNER JOIN TableB b
ON b.pid = a.pid
WHERE b.price = (SELECT MAX(price) FROM tableB)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-06-15 : 00:33:47
SELECT TOP(1) WITH TIES a.pname,n.price
FROM TableA a
INNER JOIN TableB b ON b.pid = a.pid
ORDER BY b.price DESC



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -