Using the Cartesian Product

Valid joins are essential to producing comprehensible multitable query results, unless one of the tables contains a single row—perhaps a system variable or a stored value. In that case, you can use a Cartesian product between two tables without fear. For example, test3 contains the current tax rate.

SQL
create table test3
(rate decimal not null,
date_start date not null default current date)
[table created]
insert test3 (rate)
values (.08)
[1 row]

You can use test3 with titles without a join to calculate the base-plus-tax price of books.

SQL
select title_id as Book, price as BasePrice, price + ( price * rate)
as TaxPrice
from titles, test3
where type = 'business'
order by title_id
Book    BasePrice        TaxPrice
====== ========== ===============
BU1032      29.99           32.39
BU1111      21.95           23.71
BU2075      12.99           14.03
BU7832      29.99           32.39
[4 rows]

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.151.126