Finding Data Within a Range When You Don't Know the Values
To find all the books with prices between $40.95 and $50.00, you can run a query like this:
SQL
select substr( title, 1, 30) as book, title_id, price
from titles
where price between 40.95 and 50.00
order by price
book title_id price
============================== ======== ==========
Onions, Leeks, and Garlic: Coo TC3218 40.95
Computer Phobic and Non-Phobic PS1372 41.59
But Is It User Friendly? PC1035 42.95
[3 rows]
If you want to see all books with prices between those of two particular books but you don't know the prices of the books, try something like this:
SQLselect title, title_id, price from titles where price between (select price from titles where title like 'Onions%')
Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.