hello,
Obviously, I am not a SQL coder... but I am trying to learn SQL in my spare time. Right now, I am using three different books: SQL Queries for Mere Mortals, the O'Reilly SQL Pocket Guide, and an Oracle9i SQL text that I found at a used book store (its part of Oracle's DBA cert program).
So, I need to find the answer to this:
List the most expensive book purchased by customer 1017.
I would think that this would do it:
select title, MIN(retail) from books, orders, orderitems
where orders.customer# = 1017
and orders.order# = orderitems.order#
and orderitems.isbn = books.isbn
Group by title
But it does not. IT DOES go as far as listing everything that that person ordered, but it does not show only the one item with the minimum retail cost.
How do you seperate results? If I run it without the group by, it does not work. If I try a HAVING like this:
HAVING MIN(retail) = retail
it does not work. That one I thought would work, to match only the record where the retail field matches MIN(retail) for the whole column...
any ideas?
Obviously, I am not a SQL coder... but I am trying to learn SQL in my spare time. Right now, I am using three different books: SQL Queries for Mere Mortals, the O'Reilly SQL Pocket Guide, and an Oracle9i SQL text that I found at a used book store (its part of Oracle's DBA cert program).
So, I need to find the answer to this:
List the most expensive book purchased by customer 1017.
I would think that this would do it:
select title, MIN(retail) from books, orders, orderitems
where orders.customer# = 1017
and orders.order# = orderitems.order#
and orderitems.isbn = books.isbn
Group by title
But it does not. IT DOES go as far as listing everything that that person ordered, but it does not show only the one item with the minimum retail cost.
How do you seperate results? If I run it without the group by, it does not work. If I try a HAVING like this:
HAVING MIN(retail) = retail
it does not work. That one I thought would work, to match only the record where the retail field matches MIN(retail) for the whole column...
any ideas?