views:

146

answers:

2

I need to find the book code and book title for each book whose price is greater than the book price for every book that has the type 'HOR'. My table looks like this

CREATE TABLE BOOK (
   BOOK_CODE CHAR(4) CONSTRAINT BOOK_BOOK_CODE_PK PRIMARY KEY, 
   TITLE VARCHAR2(40) CONSTRAINT BOOK_TITLE_NN NOT NULL, 
   PUBLISHER_CODE CHAR(2) CONSTRAINT BOOK_PUBLISHER_CODE_FK REFERENCES PUBLISHER(PUBLISHER_CODE),
   TYPE CHAR(3), (this is where the 'HOR' is located)
   PRICE NUMBER(4,2), 
   PAPERBACK CHAR(1) 
);

I have tried several different ways but I am at a loss. I am assuming I will have to use an alias?

+1  A: 

Not necessarily. You could use a nested SELECT like this:

SELECT
    BOOK_CODE,
    TITLE
FROM
    BOOK
WHERE
    PRICE > (SELECT MAX(PRICE) FROM BOOK WHERE TYPE = 'HOR'))
KG
You shouldn't answer questions like this until the original poster has shown what they have tried that didn't work. Giving answers without any effort being shown is encouraging people not to learn to do things themselves; one of these days, you or I could end up having to maintain code they "wrote", and I'd prefer not to have that happen.
Ken White
This is true, @Ken White. Good point.
KG
Believe me I do not want the answer as much as I want to know the reason. Believe me you are a long way away from maintaining any code that I write. I am just learning.SELECT MIKEC.BOOK_CODE, MIKEC.TITLE, MIKEC.TYPE, MIKEC.PRICE, BOOK.BOOK_CODE, BOOK.TITLE, BOOK.TYPE, BOOK.PRICEFROM BOOK, BOOK MIKECWHERE MIKEC.PRICE > BOOK.PRICEAND MIKEc.TYPE = 'HOR';I am not sure why nested works.
Mike
A: 
SELECT a.book_code, a.title
FROM book a, book b
WHERE a.price > b.price
AND b.type = 'HOR'

Possibly?

dhorn
See my comment to KG above.
Ken White
Fair enough, point received.
dhorn