Reputation: 135
Ive tried IN, multiple like clauses etc.
The problem: List BOOKs published by Jove, Penguin, Plume and Scholastic. Organize by title within publisher.
The desc table
SQL> desc book
Name
------------------
BOOK_CODE
TITLE
PUBLISHER_CODE
TYPE
PRICE
PAPERBACK
sql Ive tried
SQL> select * from BOOK where Publisher_Code IN(JP,PE,PL,SS)
2 group by Publisher_code, title;
SQL> select * from BOOK
2 where PUBLISHER_CODE IN('%JP%', '%PE%','%PL%', '%SC%')
3 group by title, Publisher_code;
SQL> select * from book
2 where Publisher_code like '%JP%'
3 OR where Publisher_code like '%PE%'
4 OR where Publisher_code like '%PL%'
5 OR where Publisher_code like '%SC%'
6 group by Publisher_code
7 order by title;
Upvotes: 0
Views: 223
Reputation: 1269503
It is unclear why you are using group by
. You want order by
. Your example queries have very basic SQL mistakes, such as repeating the where
keyword within a query. Here is a version that seems to do what you want:
select b.*
from book b
where b.Publisher_code like '%JP%' or
b.Publisher_code like '%PE%' or
b.Publisher_code like '%PL%' or
b.Publisher_code like '%SC%'
order by b.Publisher_code, b.Title;
As a note: presumably the publisher codes are constants, and you don't need to use like
with a wildcard.
Upvotes: 4