I have a table(product),It contain fields(productname,cost).
I want to retrieve the product name ,which cost is second
maximum in the table?

Answers were Sorted based on User's Feedback



I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / venkat ramana

SELECT PRODUCTNAME
FROM PRODUCT
WHERE COST < (SELECT MAX(COST)FROM PRODUCT)
ORDER BY COST DESC
FETCH FIRST 1 ROW ONLY ;

HOPE THE ABOVE QUERY WILL PROVIDE YOU THE DESIRED RESULT.

Is This Answer Correct ?    14 Yes 2 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / rajasekaran

with e as (select product_name,cost,rank() over(order by
cost desc) as rk from product) select * from e where rk=2;

Is This Answer Correct ?    3 Yes 0 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / viki

SELECT PRODUCTNAME FROM PRODUCT WHERE COST <> max(COST)

AND PRODUCTNAME=

(SELECT PRODUCTNAME FROM PRODUCT WHERE COST =
(SELECT COST FROM PRODUCT
ORDER BY COST DESC
FETCH FIRST TWO ROWS ONLY))

Is This Answer Correct ?    0 Yes 0 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / dinesh m

A)
select productname from product
where cost=(Select max(cost) from product where cost not in
(select max (cost) from product) );

Is This Answer Correct ?    0 Yes 0 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / pc

select productname from product where cost=(select max(cost) from product where cost<> (select max(cost) from product));

Is This Answer Correct ?    0 Yes 0 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / vineeth varghese

(Select product from product where cost = (Select Max (cost) from product where cost not = (select max (cost) from product)))

Is This Answer Correct ?    0 Yes 0 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / siri

select productname from product p where 2=(select count(*) from product q where p.cost<=q.cost)

Is This Answer Correct ?    0 Yes 1 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / mr. cooooool

Hi............

SELECT PRODUCTNAME FROM PRODUCT WHERE COST = (SELECT MAX(COST)
FROM PRODUCT WHERE COST > (SELECT MAX(COST) FROM PRODUCT));

THANKS
REGARDS
RAVINDRA BISHT

Is This Answer Correct ?    13 Yes 15 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / ananth

We can also use correlated subquery for this..

Select product from product a where 1 =
(select count(*) from product b where a.cost < b.cost);

Is This Answer Correct ?    0 Yes 3 No

I have a table(product),It contain fields(productname,cost). I want to retrieve the product name ,w..

Answer / pratap

A)Select product, Max (cost) from product where cost <
(select max (cost) from product);

Is This Answer Correct ?    7 Yes 13 No

Post New Answer

More DB2 Interview Questions

How to resolve -407 sql code in DB2?

9 Answers   Cap Gemini,


Give a brief description of db2 isolation levels?

0 Answers  


How does DB2 determine what lock-size to use?

2 Answers  


What is null value in db2?

0 Answers  


When can an insert of a new primary key value threaten referential integrity?

2 Answers   Mind Tree,






What is the SQL Communications Area and what are some of its key fields?

1 Answers  


What is a clustering index?

2 Answers  


What does DML stand for and what are some examples of it?

3 Answers   IBM,


in GDG: is it poosible to copy records from a file which utilizes some 100 cylinders to a gdg whose model is defined as trk(1,0) and also it possible to copy 100 bytes file to 80 bytes file?

1 Answers   IBM,


How to fetch the uncommited data from table ?

1 Answers   JPMorgan Chase,


What is referential integrity?

5 Answers  


I understand Join always perform better than subqueries. Then what is the advantage/use of Subqueries/correlated subqueries etc.,in DB2 programming.Please explain.

0 Answers  


Categories